-
Notifications
You must be signed in to change notification settings - Fork 0
Add Toast components and Refactor Button + Input #115
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 all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
60e7aab
feat(ui): add Toast and ToastCustom components, update alert and inli…
kylengn 5a46145
refactor(ui): group Button and Input components in specific folders
kylengn 04e21e2
refactor(ui): remove variant prop from ToastCustomProps for cleaner API
kylengn 64cc6f8
refactor(ui): rename ThemeProvider component and update imports for i…
kylengn c0c5cf0
Merge branch 'main' into feat/toast-and-refactor
kylengn b7ae513
feat(ui): add toast components and refactor existing code
kylengn 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@shipfox/react-ui": minor | ||
| --- | ||
|
|
||
| Add toast components and refactor |
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
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
libs/react/ui/src/components/button.tsx → ...react/ui/src/components/button/button.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
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 @@ | ||
| export * from './button'; |
2 changes: 1 addition & 1 deletion
2
libs/react/ui/src/components/dynamic-item/dynamic-item.stories.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
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
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 @@ | ||
| export * from './input'; |
File renamed without changes.
File renamed without changes.
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
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 @@ | ||
| export * from './theme-provider'; |
File renamed without changes.
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,2 @@ | ||
| export {Toaster, type ToasterProps, toast} from './toast'; | ||
| export {ToastCustom, type ToastCustomProps} from './toast-custom'; |
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,154 @@ | ||
| import {cva, type VariantProps} from 'class-variance-authority'; | ||
| import {Icon} from 'components/icon/icon'; | ||
| import type {ReactNode} from 'react'; | ||
| import {cn} from 'utils/cn'; | ||
|
|
||
| const toastCustomVariants = cva('group relative flex items-start gap-8', { | ||
| variants: { | ||
| variant: { | ||
| default: 'text-tag-neutral-icon', | ||
| info: 'text-tag-neutral-icon', | ||
| success: 'text-tag-success-icon', | ||
| warning: 'text-tag-warning-icon', | ||
| error: 'text-tag-error-icon', | ||
| }, | ||
| }, | ||
| defaultVariants: { | ||
| variant: 'default', | ||
| }, | ||
| }); | ||
|
|
||
| export type ToastAction = { | ||
| label: string; | ||
| onClick: () => void; | ||
| }; | ||
|
|
||
| export type ToastCustomProps = VariantProps<typeof toastCustomVariants> & { | ||
| title?: string; | ||
| description?: string; | ||
| content?: string; | ||
| actions?: ToastAction[]; | ||
| onClose?: () => void; | ||
| className?: string; | ||
| }; | ||
|
|
||
| function getDefaultIcon(variant: ToastCustomProps['variant'] = 'default'): ReactNode { | ||
| switch (variant) { | ||
| case 'info': | ||
| return <Icon name="info" size={20} />; | ||
| case 'success': | ||
| return <Icon name="checkCircleSolid" size={20} />; | ||
| case 'warning': | ||
| return <Icon name="info" size={20} />; | ||
| case 'error': | ||
| return <Icon name="xCircleSolid" size={20} />; | ||
| default: | ||
| return <Icon name="info" size={20} />; | ||
| } | ||
| } | ||
|
|
||
| export function ToastCustom({ | ||
| variant = 'default', | ||
| title, | ||
| description, | ||
| content, | ||
| actions, | ||
| onClose, | ||
| className, | ||
| }: ToastCustomProps) { | ||
| const hasTitle = Boolean(title); | ||
| const hasDescription = Boolean(description); | ||
| const hasContent = Boolean(content); | ||
| const hasActions = Boolean(actions && actions.length > 0); | ||
| const isSimple = hasContent && !hasTitle && !hasDescription; | ||
|
|
||
| return ( | ||
| <div data-slot="toast-custom" className={cn(toastCustomVariants({variant}), className)}> | ||
| <div className="w-20 h-20 rounded-full flex items-start justify-center shrink-0 pt-1"> | ||
| {getDefaultIcon(variant)} | ||
| </div> | ||
|
|
||
| <div className="flex-1 min-w-0"> | ||
| {hasTitle && ( | ||
| <div | ||
| data-slot="toast-custom-title" | ||
| className="font-medium text-sm leading-20 text-foreground-neutral-base mb-4" | ||
| > | ||
| {title} | ||
| </div> | ||
| )} | ||
| {hasDescription && ( | ||
| <div | ||
| data-slot="toast-custom-description" | ||
| className="text-xs leading-20 text-foreground-neutral-muted mb-8" | ||
| > | ||
| {description} | ||
| </div> | ||
| )} | ||
| {isSimple ? ( | ||
| <div className="flex items-center justify-between gap-16 min-w-400 mr-30"> | ||
kylengn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <div | ||
| data-slot="toast-custom-content" | ||
| className="text-sm leading-20 text-foreground-neutral-base" | ||
| > | ||
| {content} | ||
| </div> | ||
| {hasActions && ( | ||
| <div data-slot="toast-custom-actions" className="flex items-center gap-16"> | ||
| {actions?.map((action) => ( | ||
| <button | ||
| key={action.label} | ||
| data-slot="toast-custom-action" | ||
| type="button" | ||
| onClick={action.onClick} | ||
| className="bg-transparent border-none p-0 cursor-pointer text-xs font-medium leading-20 text-foreground-neutral-base hover:text-foreground-neutral-subtle transition-colors duration-150 outline-none focus-visible:ring-2 focus-visible:ring-background-accent-blue-base focus-visible:ring-offset-2" | ||
| > | ||
| {action.label} | ||
| </button> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ) : ( | ||
| <> | ||
| {hasContent && !hasTitle && ( | ||
| <div | ||
| data-slot="toast-custom-content" | ||
| className="text-sm leading-20 text-foreground-neutral-base mb-8" | ||
| > | ||
| {content} | ||
| </div> | ||
| )} | ||
| {hasActions && ( | ||
| <div data-slot="toast-custom-actions" className="flex items-center gap-16 mt-8"> | ||
| {actions?.map((action) => ( | ||
| <button | ||
| key={action.label} | ||
| data-slot="toast-custom-action" | ||
| type="button" | ||
| onClick={action.onClick} | ||
| className="bg-transparent border-none p-0 cursor-pointer text-xs font-medium leading-20 text-foreground-neutral-base hover:text-foreground-neutral-subtle transition-colors duration-150 outline-none focus-visible:ring-2 focus-visible:ring-background-accent-blue-base focus-visible:ring-offset-2" | ||
| > | ||
| {action.label} | ||
| </button> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </> | ||
| )} | ||
| </div> | ||
|
|
||
| {onClose && ( | ||
| <button | ||
| data-slot="toast-custom-close" | ||
| type="button" | ||
| onClick={onClose} | ||
| className="absolute cursor-pointer -top-2 -right-2 rounded-4 p-4 bg-transparent border-none text-foreground-neutral-muted hover:text-foreground-neutral-base hover:bg-background-components-hover transition-colors duration-150 outline-none focus-visible:ring-2 focus-visible:ring-background-accent-blue-base focus-visible:ring-offset-2 shrink-0" | ||
| aria-label="Close" | ||
| > | ||
| <Icon name="close" className="w-16 h-16" /> | ||
| </button> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
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.