-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(apps-ui-kit): add
Button
component (#1010)
* feat(ui): kickoff * feat(ui): update package name * feat(ui): update headers * refactor: move folders around and add aliases * fix: cleanup exports field in package.json * fix: update alias import to use "@" * fix: manypkg check * feat: add configs necessary for the package * fix: update styles import * fix(tooling-ui): linter * refactor!: rename folder * refactor: rename missing strings * fix!: revert and update lockfile * feat(wip): add custom tailwind palettes * feat: add necessary palettes for tailwind * fix: remove unused file * feat: add header to css files * fix: remove change * refactor: format files * fix: update import route * feat(tooling/ui): add button component * fix: add missing scales to tailwind * fix: update border radius and color tertiary * fix: update paddings to new scaling * feat(tooling-ui): add darkmode with an example button * fix: run manypkg fix * feat: add dark and light modes to `Button` * refactor: update tsconfig and use a different file for package compilation * fix: update opacity 8 to be `0.08` instead of `0.8` * manypkg fix * fix: formatting * regenerate lock file * fix: formatting * feat: add enums alias to tsconfig * feat: use tailwindcss darkmode for classes * refactor: remove unused file * fix: remove export * fix: remove outdated styling * fix: add correct export * feat: add shader color palette * fix: improve name of shaders * feat(tooling-ui): add support for darkmode in storybook (#1022) * feat(tooling-ui): add darkmode with an example button * fix: run manypkg fix * regenerate lock file * feat: use tailwindcss darkmode for classes * refactor: remove unused file * fix: remove export * chore: remove debris from story --------- Co-authored-by: marc2332 <[email protected]> * fix: format * fix: Button story props --------- Co-authored-by: evavirseda <[email protected]> Co-authored-by: cpl121 <[email protected]> Co-authored-by: cpl121 <[email protected]> Co-authored-by: Bran <[email protected]> Co-authored-by: Marc Espin <[email protected]>
- Loading branch information
1 parent
6666ba3
commit 9f9acdd
Showing
13 changed files
with
276 additions
and
109 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
module.exports = { | ||
plugins: { | ||
'tailwindcss/nesting': {}, | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
|
This file was deleted.
Oops, something went wrong.
This file contains 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,72 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import React from 'react'; | ||
import { ButtonSize, ButtonType } from './button.enums'; | ||
import { | ||
PADDINGS, | ||
PADDINGS_ONLY_ICON, | ||
BACKGROUND_COLORS, | ||
TEXT_COLORS, | ||
TEXT_CLASSES, | ||
TEXT_COLOR_DISABLED, | ||
DISABLED_BACKGROUND_COLORS, | ||
} from './button.classes'; | ||
import cx from 'classnames'; | ||
|
||
interface ButtonProps { | ||
/** | ||
* The size of the button. | ||
*/ | ||
size?: ButtonSize; | ||
/** | ||
* The type of the button | ||
*/ | ||
type?: ButtonType; | ||
/** | ||
* The text of the button. | ||
*/ | ||
text?: string; | ||
/** | ||
The icon of the button | ||
*/ | ||
icon?: React.ReactNode; | ||
/** | ||
* The button is disabled or not. | ||
*/ | ||
disabled?: boolean; | ||
/** | ||
* The onClick event of the button. | ||
*/ | ||
onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void; | ||
} | ||
|
||
export function Button({ | ||
icon, | ||
text, | ||
disabled, | ||
onClick, | ||
size = ButtonSize.Medium, | ||
type = ButtonType.Primary, | ||
}: ButtonProps): React.JSX.Element { | ||
const paddingClasses = icon && !text ? PADDINGS_ONLY_ICON[size] : PADDINGS[size]; | ||
const textSizes = TEXT_CLASSES[size]; | ||
const backgroundColors = disabled ? DISABLED_BACKGROUND_COLORS[type] : BACKGROUND_COLORS[type]; | ||
const textColors = disabled ? TEXT_COLOR_DISABLED[type] : TEXT_COLORS[type]; | ||
return ( | ||
<button | ||
onClick={onClick} | ||
className={cx( | ||
'state-layer relative flex rounded-full disabled:opacity-40', | ||
paddingClasses, | ||
backgroundColors, | ||
)} | ||
disabled={disabled} | ||
> | ||
<div className="flex flex-row items-center justify-center gap-2"> | ||
{icon && <span className={cx(textColors)}>{icon}</span>} | ||
{text && <span className={cx('font-inter', textColors, textSizes)}>{text}</span>} | ||
</div> | ||
</button> | ||
); | ||
} |
53 changes: 53 additions & 0 deletions
53
apps/ui-kit/src/lib/components/atoms/button/button.classes.ts
This file contains 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 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { ButtonSize, ButtonType } from './button.enums'; | ||
|
||
export const PADDINGS: Record<ButtonSize, string> = { | ||
[ButtonSize.Small]: 'px-md py-xs', | ||
[ButtonSize.Medium]: 'px-md py-sm', | ||
}; | ||
|
||
export const PADDINGS_ONLY_ICON: Record<ButtonSize, string> = { | ||
[ButtonSize.Small]: 'p-xs', | ||
[ButtonSize.Medium]: 'p-sm', | ||
}; | ||
|
||
export const BACKGROUND_COLORS: Record<ButtonType, string> = { | ||
[ButtonType.Primary]: 'bg-primary-30', | ||
[ButtonType.Secondary]: 'bg-neutral-90 dark:bg-neutral-20', | ||
[ButtonType.Ghost]: 'bg-transparent', | ||
[ButtonType.Outlined]: 'bg-transparent border border-neutral-50', | ||
[ButtonType.Destructive]: 'bg-error-90', | ||
}; | ||
|
||
export const DISABLED_BACKGROUND_COLORS: Record<ButtonType, string> = { | ||
[ButtonType.Primary]: 'bg-neutral-80 dark:bg-neutral-30', | ||
[ButtonType.Secondary]: 'bg-neutral-90 dark:bg-neutral-20', | ||
[ButtonType.Ghost]: 'bg-transparent', | ||
[ButtonType.Outlined]: 'bg-transparent border border-neutral-50', | ||
[ButtonType.Destructive]: 'bg-error-90', | ||
}; | ||
|
||
const DEFAULT_TEXT_COLORS: string = 'text-neutral-10 dark:text-neutral-92'; | ||
|
||
export const TEXT_COLORS: Record<ButtonType, string> = { | ||
[ButtonType.Primary]: 'text-primary-100', | ||
[ButtonType.Secondary]: DEFAULT_TEXT_COLORS, | ||
[ButtonType.Ghost]: DEFAULT_TEXT_COLORS, | ||
[ButtonType.Outlined]: DEFAULT_TEXT_COLORS, | ||
[ButtonType.Destructive]: 'text-error-20', | ||
}; | ||
|
||
export const TEXT_CLASSES: Record<ButtonSize, string> = { | ||
[ButtonSize.Small]: 'text-label-md', | ||
[ButtonSize.Medium]: 'text-label-lg', | ||
}; | ||
|
||
export const TEXT_COLOR_DISABLED: Record<ButtonType, string> = { | ||
[ButtonType.Primary]: DEFAULT_TEXT_COLORS, | ||
[ButtonType.Secondary]: DEFAULT_TEXT_COLORS, | ||
[ButtonType.Ghost]: DEFAULT_TEXT_COLORS, | ||
[ButtonType.Outlined]: DEFAULT_TEXT_COLORS, | ||
[ButtonType.Destructive]: 'text-error-20', | ||
}; |
15 changes: 15 additions & 0 deletions
15
apps/ui-kit/src/lib/components/atoms/button/button.enums.ts
This file contains 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,15 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export enum ButtonSize { | ||
Small = 'small', | ||
Medium = 'medium', | ||
} | ||
|
||
export enum ButtonType { | ||
Primary = 'primary', | ||
Secondary = 'secondary', | ||
Ghost = 'ghost', | ||
Outlined = 'outlined', | ||
Destructive = 'destructive', | ||
} |
This file contains 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,6 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './Button'; | ||
|
||
export * from './button.enums'; |
This file contains 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,4 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
export * from './button'; |
This file contains 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 |
---|---|---|
|
@@ -3,4 +3,4 @@ | |
|
||
import '../styles/index.css'; | ||
|
||
export * from './Button'; | ||
export * from './atoms'; |
This file contains 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 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
Oops, something went wrong.