Skip to content

Commit

Permalink
feat(Kbd): add contrast colors
Browse files Browse the repository at this point in the history
  • Loading branch information
driss-chelouati committed Feb 19, 2024
1 parent 0dee570 commit 715c431
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 4 deletions.
30 changes: 28 additions & 2 deletions src/plugins/components/kbd/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,38 @@ export default plugin(({ addComponents, theme }) => {
},
//Color:default
'&.nui-kbd-default': {
'@apply bg-white dark:bg-muted-800 border border-b-2 border-muted-500/20 dark:border-muted-300/20':
//Background
[`@apply bg-${config.color.default.background.light} dark:bg-${config.color.default.background.dark} border border-b-2`]:
{},
//Border
[`@apply border-${config.color.default.border.light} dark:border-${config.color.default.border.dark}`]:
{},
},
//Color:default-contrast
'&.nui-kbd-default-contrast': {
//Background
[`@apply bg-${config.color.defaultContrast.background.light} dark:bg-${config.color.defaultContrast.background.dark} border border-b-2`]:
{},
//Border
[`@apply border-${config.color.defaultContrast.border.light} dark:border-${config.color.defaultContrast.border.dark}`]:
{},
},
//Color:muted
'&.nui-kbd-muted': {
'@apply bg-muted-50 dark:bg-muted-800 border border-b-2 border-muted-600/20 dark:border-muted-300/20':
//Background
[`@apply bg-${config.color.muted.background.light} dark:bg-${config.color.muted.background.dark} border border-b-2`]:
{},
//Border
[`@apply border-${config.color.muted.border.light} dark:border-${config.color.muted.border.dark}`]:
{},
},
//Color:muted-contrast
'&.nui-kbd-muted-contrast': {
//Background
[`@apply bg-${config.color.mutedContrast.background.light} dark:bg-${config.color.mutedContrast.background.dark} border border-b-2`]:
{},
//Border
[`@apply border-${config.color.mutedContrast.border.light} dark:border-${config.color.mutedContrast.border.dark}`]:
{},
},
},
Expand Down
20 changes: 20 additions & 0 deletions src/plugins/components/kbd/kbd.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ export const defaultConfig = {
dark: 'muted-300/20',
},
},
defaultContrast: {
background: {
light: 'white',
dark: 'muted-950',
},
border: {
light: 'muted-500/20',
dark: 'muted-400/20',
},
},
muted: {
background: {
light: 'muted-50',
Expand All @@ -113,6 +123,16 @@ export const defaultConfig = {
dark: 'muted-300/20',
},
},
mutedContrast: {
background: {
light: 'muted-50',
dark: 'muted-950',
},
border: {
light: 'muted-600/20',
dark: 'muted-400/20',
},
},
},
}

Expand Down
26 changes: 26 additions & 0 deletions src/plugins/components/kbd/kbd.doc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ Kbd elements can have different sizes and colors. Below is an eample of availabl

<br />

### Color: default-contrast

Kbd elements can have different sizes and colors. Below is an eample of available sizes and with the default contrast color.

<div className="flex items-end gap-4 border border-muted-200 dark:border-muted-800 bg-white dark:bg-slate-900 p-6 rounded-sm">
<Story of={KbdStories.DefaultContrastXs} />
<Story of={KbdStories.DefaultContrastSm} />
<Story of={KbdStories.DefaultContrastMd} />
<Story of={KbdStories.DefaultContrastLg} />
</div>

<br />

### Color: muted

Kbd elements can have different sizes and colors. Below is an eample of available sizes and with the muted color.
Expand All @@ -43,6 +56,19 @@ Kbd elements can have different sizes and colors. Below is an eample of availabl

<br />

### Color: muted-contrast

Kbd elements can have different sizes and colors. Below is an eample of available sizes and with the muted contrast color.

<div className="flex items-end gap-4 border border-muted-200 dark:border-muted-800 bg-white dark:bg-slate-900 p-6 rounded-sm">
<Story of={KbdStories.MutedContrastXs} />
<Story of={KbdStories.MutedContrastSm} />
<Story of={KbdStories.MutedContrastMd} />
<Story of={KbdStories.MutedContrastLg} />
</div>

<br />

### Slot: icon

Kbd elements can have an icon inside instead of text. Below is an eample of available icon sizes.
Expand Down
90 changes: 89 additions & 1 deletion src/plugins/components/kbd/kbd.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const meta = {
},
color: {
control: { type: 'select' },
options: ['default', 'muted'],
options: ['default', 'default-contrast', 'muted', 'muted-contrast'],
defaultValue: 'default',
},
rounded: {
Expand Down Expand Up @@ -87,6 +87,48 @@ export const DefaultLg: Story = {
}
// #endregion

// #region Default Contrast
export const DefaultContrastXs: Story = {
name: 'Default contrast: xs',
args: {
size: 'xs',
children: html`
Esc
`,
},
}

export const DefaultContrastSm: Story = {
name: 'Default contrast: sm',
args: {
size: 'sm',
children: html`
Esc
`,
},
}

export const DefaultContrastMd: Story = {
name: 'Default contrast: md',
args: {
size: 'md',
children: html`
Esc
`,
},
}

export const DefaultContrastLg: Story = {
name: 'Default contrast: lg',
args: {
size: 'lg',
children: html`
Esc
`,
},
}
// #endregion

// #region Muted
export const MutedXs: Story = {
name: 'Muted: xs',
Expand Down Expand Up @@ -133,6 +175,52 @@ export const MutedLg: Story = {
}
// #endregion

// #region Muted Contrast
export const MutedContrastXs: Story = {
name: 'Muted contrast: xs',
args: {
size: 'xs',
color: 'muted',
children: html`
Esc
`,
},
}

export const MutedContrastSm: Story = {
name: 'Muted contrast: sm',
args: {
size: 'sm',
color: 'muted',
children: html`
Esc
`,
},
}

export const MutedContrastMd: Story = {
name: 'Muted contrast: md',
args: {
size: 'md',
color: 'muted',
children: html`
Esc
`,
},
}

export const MutedContrastLg: Story = {
name: 'Muted contrast: lg',
args: {
size: 'lg',
color: 'muted',
children: html`
Esc
`,
},
}
// #endregion

// #region Icon
export const IconXs: Story = {
name: 'Icon: xs',
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/components/kbd/kbd.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { PropertyVariant } from '~/types/utils'
export interface KbdProps extends Record<string, unknown> {
rounded?: 'none' | 'sm' | 'md' | 'lg' | 'full'
size?: 'xs' | 'sm' | 'md' | 'lg'
color?: 'default' | 'muted'
color?: 'default' | 'default-contrast' | 'muted' | 'muted-contrast'
classes?: {
wrapper?: string | string[]
}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/components/kbd/kbd.variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ export const size = {

export const color = {
default: 'nui-kbd-default',
'default-contrast': 'nui-kbd-default-contrast',
muted: 'nui-kbd-muted',
'muted-contrast': 'nui-kbd-muted-contrast',
} as const satisfies KbdVariant<'color'>

0 comments on commit 715c431

Please sign in to comment.