-
-
Notifications
You must be signed in to change notification settings - Fork 122
Add support of discords "new" components v2! #193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c12172c
Initial commit of components v2
TheMonDon 08db6f6
Run lint lol
TheMonDon e98cada
Requested changes + bug fixes
TheMonDon bafe7ff
refactor the const over to function + spelling
TheMonDon 130b2fa
Merge branch 'master' into components-v2
ItzDerock ba19c99
fix linting error
ItzDerock 293783a
add script to send componentv2 tests
ItzDerock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import React from 'react'; | ||
|
|
||
| const DiscordContainer: React.FC<{ children: React.ReactNode }> = ({ children }) => { | ||
| return ( | ||
| <div | ||
| style={{ | ||
| display: 'flex', | ||
| width: '500px', | ||
| flexDirection: 'column', | ||
| backgroundColor: '#3f4248', | ||
| padding: '16px', | ||
| border: '1px solid #4f5359', | ||
| marginTop: '2px', | ||
| marginBottom: '2px', | ||
| borderRadius: '10px', | ||
| gap: '8px', | ||
| }} | ||
| > | ||
| {children} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default DiscordContainer; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import React from 'react'; | ||
| import type { MediaGalleryComponent } from 'discord.js'; | ||
| import { getGalleryLayout, getImageStyle } from './utils'; | ||
|
|
||
| const DiscordMediaGallery: React.FC<{ component: MediaGalleryComponent }> = ({ component }) => { | ||
| if (!component.items || component.items.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| const count = component.items.length; | ||
| const imagesToShow = component.items.slice(0, 10); | ||
| const hasMore = component.items.length > 10; | ||
|
|
||
| return ( | ||
| <div style={getGalleryLayout(count)}> | ||
| {imagesToShow.map((media, idx) => ( | ||
| <div key={idx} style={getImageStyle(idx, count)}> | ||
| <img | ||
| src={media.media.url} | ||
| alt={media.description || 'Media content'} | ||
| style={{ | ||
| width: '100%', | ||
| height: '100%', | ||
| objectFit: 'cover', | ||
| }} | ||
| /> | ||
| {hasMore && idx === imagesToShow.length - 1 && ( | ||
| <div | ||
| style={{ | ||
| position: 'absolute', | ||
| top: 0, | ||
| left: 0, | ||
| width: '100%', | ||
| height: '100%', | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| backgroundColor: 'rgba(0, 0, 0, 0.7)', | ||
| color: 'white', | ||
| fontSize: '20px', | ||
| fontWeight: 'bold', | ||
| }} | ||
| > | ||
| +{component.items.length - 10} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default DiscordMediaGallery; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import React from 'react'; | ||
| import { type MessageActionRowComponent, ComponentType } from 'discord.js'; | ||
| import { parseDiscordEmoji } from '../../../utils/utils'; | ||
| import { getSelectTypeLabel } from './utils'; | ||
| import { selectMenuStyle } from './styles'; | ||
|
|
||
| const DiscordSelectMenu: React.FC<{ | ||
|
TheMonDon marked this conversation as resolved.
Outdated
|
||
| component: Exclude<MessageActionRowComponent, { type: ComponentType.Button }>; | ||
| }> = ({ component }) => { | ||
| const isStringSelect = component.type === ComponentType.StringSelect; | ||
| const placeholder = component.placeholder || getSelectTypeLabel(component.type); | ||
|
|
||
| return ( | ||
| <div style={selectMenuStyle}> | ||
| <div style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{placeholder}</div> | ||
| <div style={{ display: 'flex', alignItems: 'center', marginLeft: '8px' }}> | ||
| <svg width="24" height="24" viewBox="0 0 24 24"> | ||
| <path fill="currentColor" d="M7 10L12 15L17 10H7Z" /> | ||
| </svg> | ||
| </div> | ||
| {isStringSelect && component.options && component.options.length > 0 && ( | ||
| <div | ||
| style={{ | ||
| display: 'none', | ||
| position: 'absolute', | ||
| top: '44px', | ||
| left: '0', | ||
| width: '100%', | ||
| backgroundColor: '#2b2d31', | ||
| borderRadius: '4px', | ||
| zIndex: 10, | ||
| border: '1px solid #1e1f22', | ||
| maxHeight: '320px', | ||
| overflowY: 'auto', | ||
| }} | ||
| > | ||
| {component.options.map((option, idx) => ( | ||
| <div | ||
| key={idx} | ||
| style={{ | ||
| padding: '8px 12px', | ||
| cursor: 'pointer', | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| borderBottom: idx < component.options.length - 1 ? '1px solid #1e1f22' : 'none', | ||
| }} | ||
| > | ||
| {option.emoji && <span style={{ marginRight: '8px' }}>{parseDiscordEmoji(option.emoji)}</span>} | ||
| <span>{option.label}</span> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default DiscordSelectMenu; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import React from 'react'; | ||
| import { SeparatorSpacingSize } from 'discord.js'; | ||
|
|
||
| const DiscordSeperator: React.FC<{ divider: boolean; spacing: SeparatorSpacingSize }> = ({ divider, spacing }) => { | ||
| return ( | ||
| <div | ||
| style={{ | ||
| width: '100%', | ||
| height: divider ? '1px' : '0px', | ||
| backgroundColor: '#4f5359', | ||
| margin: spacing === SeparatorSpacingSize.Large ? '8px 0' : '0', | ||
| }} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| export default DiscordSeperator; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import React from 'react'; | ||
| import type { ButtonComponent, ThumbnailComponent } from 'discord.js'; | ||
| import { Component } from '../../components'; | ||
| import SectionContent from './SectionContent'; | ||
| import SectionAccessory from './SectionAccessory'; | ||
|
|
||
| interface DiscordSectionProps { | ||
| children: React.ReactNode; | ||
| accessory?: ButtonComponent | ThumbnailComponent; | ||
| id: number; | ||
| } | ||
|
|
||
| const DiscordSection: React.FC<DiscordSectionProps> = ({ children, accessory, id }) => { | ||
| return ( | ||
| <div | ||
| style={{ | ||
| display: 'flex', | ||
| flexDirection: 'row', | ||
| width: '100%', | ||
| maxWidth: '500px', | ||
| }} | ||
| > | ||
| <SectionContent>{children}</SectionContent> | ||
| <SectionAccessory>{accessory && <Component component={accessory} id={id} />}</SectionAccessory> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default DiscordSection; |
25 changes: 25 additions & 0 deletions
25
src/generator/renderers/components/section/SectionAccessory.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import React from 'react'; | ||
|
|
||
| interface SectionAccessoryProps { | ||
| children?: React.ReactNode; | ||
| } | ||
|
|
||
| const SectionAccessory: React.FC<SectionAccessoryProps> = ({ children }) => { | ||
| if (!children) return null; | ||
|
|
||
| return ( | ||
| <div | ||
| style={{ | ||
| display: 'flex', | ||
| width: '100%', | ||
| maxWidth: '500px', | ||
| justifyContent: 'flex-end', | ||
| alignItems: 'center', | ||
| }} | ||
| > | ||
| {children} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default SectionAccessory; |
21 changes: 21 additions & 0 deletions
21
src/generator/renderers/components/section/SectionContent.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import React from 'react'; | ||
|
|
||
| interface SectionContentProps { | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| const SectionContent: React.FC<SectionContentProps> = ({ children }) => { | ||
| return ( | ||
| <div | ||
| style={{ | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| width: '100%', | ||
| }} | ||
| > | ||
| {children} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default SectionContent; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.