Skip to content

Commit

Permalink
feat(Snack/ButtonClose): add xs size to snack, add size prop to butto…
Browse files Browse the repository at this point in the history
…n close
  • Loading branch information
driss-chelouati committed Dec 10, 2023
1 parent 7911dc8 commit 11172f4
Show file tree
Hide file tree
Showing 14 changed files with 433 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/plugins/components/button-close/button-close.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as variants from './button-close.variants'
export const ButtonClose = ({
rounded,
color = 'default',
size = 'sm',
classes,
onClick,
...attrs
Expand All @@ -19,6 +20,7 @@ export const ButtonClose = ({
class=${[
'nui-button-close',
variants.color[color],
variants.size[size],
rounded && variants.rounded[rounded],
classes?.wrapper,
]
Expand Down
22 changes: 18 additions & 4 deletions src/plugins/components/button-close/button-close.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
export const key = 'buttonClose' as const

export const defaultConfig = {
size: '9',
size: {
xs: {
outer: '6',
inner: '3',
},
sm: {
outer: '8',
inner: '4',
},
md: {
outer: '10',
inner: '4',
},
lg: {
outer: '12',
inner: '5',
},
},
rounded: {
none: 'rounded-none',
sm: 'rounded',
Expand Down Expand Up @@ -137,9 +154,6 @@ export const defaultConfig = {
},
},
},
icon: {
size: '4',
},
transition: {
property: 'colors',
duration: '300',
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/components/button-close/button-close.doc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ In any application, you need a button that serves as a trigger to close or dismi

<br />

### Sizes

Close buttons can have different sizes. Below is an example of the available sizes.

<div className="flex items-end gap-3 border border-muted-200 dark:border-muted-800 bg-white dark:bg-muted-900 p-6 rounded-sm">
<Story of={ButtonCloseStories.SizeXs} />
<Story of={ButtonCloseStories.SizeSm} />
<Story of={ButtonCloseStories.SizeMd} />
<Story of={ButtonCloseStories.SizeLg} />
</div>

<br />

### Color: default

Close buttons can have different colors. Below is an example of the default color.
Expand Down
43 changes: 43 additions & 0 deletions src/plugins/components/button-close/button-close.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const meta = {
// tags: ['autodocs'],
render: (args) => ButtonClose(args),
argTypes: {
size: {
control: { type: 'select' },
options: ['xs', 'sm', 'md', 'lg'],
defaultValue: 'md',
},
color: {
control: { type: 'select' },
options: [
Expand Down Expand Up @@ -49,6 +54,44 @@ export const Main: Story = {
}
// #endregion

// #region Sizes
export const SizeXs: Story = {
name: 'Size: xs',
args: {
color: 'muted',
size: 'xs',
rounded: 'md',
},
}

export const SizeSm: Story = {
name: 'Size: sm',
args: {
color: 'muted',
size: 'sm',
rounded: 'md',
},
}

export const SizeMd: Story = {
name: 'Size: md',
args: {
color: 'muted',
size: 'md',
rounded: 'md',
},
}

export const SizeLg: Story = {
name: 'Size: lg',
args: {
color: 'muted',
size: 'lg',
rounded: 'md',
},
}
// #endregion

// #region Color: default
export const DefaultStraight: Story = {
name: 'Default: none',
Expand Down
1 change: 1 addition & 0 deletions src/plugins/components/button-close/button-close.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { PropertyVariant } from '~/types/utils'

export interface ButtonCloseProps extends Record<string, unknown> {
rounded?: 'none' | 'sm' | 'md' | 'lg' | 'full'
size?: 'xs' | 'sm' | 'md' | 'lg'
color?:
| 'default'
| 'muted'
Expand Down
7 changes: 7 additions & 0 deletions src/plugins/components/button-close/button-close.variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ export const rounded = {
full: 'nui-button-full',
} as const satisfies ButtonCloseVariant<'rounded'>

export const size = {
xs: 'nui-button-xs',
sm: 'nui-button-sm',
md: 'nui-button-md',
lg: 'nui-button-lg',
} as const satisfies ButtonCloseVariant<'size'>

export const color = {
default: 'nui-button-default',
muted: 'nui-button-muted',
Expand Down
41 changes: 35 additions & 6 deletions src/plugins/components/button-close/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,44 @@ export default plugin.withOptions(
[`.${prefix}button-close`]: {
[`@apply ${prefix}focus flex items-center justify-center disabled:opacity-30 cursor-pointer`]:
{},
//Size
[`@apply h-${config.size} w-${config.size}`]: {},
//Transition
[`@apply transition-${config.transition.property} duration-${config.transition.duration}`]:
{},
//Icon
[`.${prefix}button-icon`]: {
[`@apply h-${config.icon.size} w-${config.icon.size} fill-current`]:
{},
//Size:xs
[`&.${prefix}button-xs`]: {
[`@apply h-${config.size.xs.outer} w-${config.size.xs.outer}`]: {},
//Icon
[`.${prefix}button-icon`]: {
[`@apply h-${config.size.xs.inner} w-${config.size.xs.inner} fill-current`]:
{},
},
},
//Size:sm
[`&.${prefix}button-sm`]: {
[`@apply h-${config.size.sm.outer} w-${config.size.sm.outer}`]: {},
//Icon
[`.${prefix}button-icon`]: {
[`@apply h-${config.size.sm.inner} w-${config.size.sm.inner} fill-current`]:
{},
},
},
//Size:md
[`&.${prefix}button-md`]: {
[`@apply h-${config.size.md.outer} w-${config.size.md.outer}`]: {},
//Icon
[`.${prefix}button-icon`]: {
[`@apply h-${config.size.md.inner} w-${config.size.md.inner} fill-current`]:
{},
},
},
//Size:lg
[`&.${prefix}button-lg`]: {
[`@apply h-${config.size.lg.outer} w-${config.size.lg.outer}`]: {},
//Icon
[`.${prefix}button-icon`]: {
[`@apply h-${config.size.lg.inner} w-${config.size.lg.inner} fill-current`]:
{},
},
},
//Rounded:sm
[`&.${prefix}button-rounded`]: {
Expand Down
53 changes: 48 additions & 5 deletions src/plugins/components/snack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default plugin.withOptions(
//Snack:text
[`.${prefix}snack-text`]: {
//Font
[`@apply font-${config.font.family} text-${config.font.size}`]: {},
[`@apply font-${config.font.family}`]: {},
//Color
[`@apply text-${config.font.color.light} dark:text-${config.font.color.dark}`]:
{},
Expand All @@ -52,8 +52,46 @@ export default plugin.withOptions(
[`.${prefix}snack-button`]: {
[`@apply hover:!bg-transparent`]: {},
},
//Size:xs
[`&.${prefix}snack-xs`]: {
//Snack:media:xs
[`&:not(.${prefix}has-media)`]: {
[`@apply !ps-2`]: {},
},
//Snack:text
[`.${prefix}snack-text`]: {
//Font
[`@apply text-${config.size.xs.font.size}`]: {},
},
//Size
[`@apply h-${config.size.xs.size}`]: {},
//Snack:icon
[`.${prefix}snack-icon`]: {
[`@apply w-${config.size.xs.icon.outer.size} h-${config.size.xs.icon.outer.size}`]:
{},
},
//Icon:inner
[`.${prefix}snack-icon-inner`]: {
[`@apply h-${config.size.xs.icon.inner.size} w-${config.size.xs.icon.inner.size}`]:
{},
},
//Snack:image
[`.${prefix}snack-image, .${prefix}snack-image-inner`]: {
[`@apply w-${config.size.xs.image.outer.size} h-${config.size.xs.image.outer.size}`]:
{},
},
},
//Size:sm
[`&.${prefix}snack-sm`]: {
//Snack:media:sm
[`&:not(.${prefix}has-media)`]: {
[`@apply !ps-3`]: {},
},
//Snack:text
[`.${prefix}snack-text`]: {
//Font
[`@apply text-${config.size.sm.font.size}`]: {},
},
//Size
[`@apply h-${config.size.sm.size}`]: {},
//Snack:icon
Expand All @@ -74,6 +112,15 @@ export default plugin.withOptions(
},
//Size:md
[`&.${prefix}snack-md`]: {
//Snack:media:md
[`&:not(.${prefix}has-media)`]: {
[`@apply !ps-4`]: {},
},
//Snack:text
[`.${prefix}snack-text`]: {
//Font
[`@apply text-${config.size.md.font.size}`]: {},
},
//Size
[`@apply h-${config.size.md.size}`]: {},
//Snack:icon
Expand Down Expand Up @@ -106,10 +153,6 @@ export default plugin.withOptions(
[`@apply bg-${config.color.muted.background.light} dark:bg-${config.color.muted.background.dark}`]:
{},
},
//Snack:media
[`&:not(.${prefix}has-media)`]: {
[`@apply ps-4`]: {},
},
},
})
}
Expand Down
39 changes: 33 additions & 6 deletions src/plugins/components/snack/snack.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,39 @@ export const Snack = ({
<span class="nui-snack-text">
<slot>${label}</slot>
</span>
${ButtonClose({
shape: 'full',
classes: {
wrapper: 'nui-snack-button scale-75',
},
})}
${size === 'xs'
? html`
${ButtonClose({
rounded: 'full',
size: 'xs',
classes: {
wrapper: 'nui-snack-button scale-75',
},
})}
`
: ''}
${size === 'sm'
? html`
${ButtonClose({
rounded: 'full',
size: 'sm',
classes: {
wrapper: 'nui-snack-button scale-75',
},
})}
`
: ''}
${size === 'md'
? html`
${ButtonClose({
rounded: 'full',
size: 'md',
classes: {
wrapper: 'nui-snack-button scale-75',
},
})}
`
: ''}
</div>
`
}
29 changes: 28 additions & 1 deletion src/plugins/components/snack/snack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,39 @@ export const defaultConfig = {
},
font: {
family: 'sans',
size: 'sm',
color: {
light: 'muted-600',
dark: 'muted-300',
},
},
size: {
xs: {
size: '6',
font: {
size: 'xs',
},
icon: {
outer: {
size: '6',
},
inner: {
size: '3',
},
},
image: {
outer: {
size: '6',
},
inner: {
size: '6',
},
},
},
sm: {
size: '8',
font: {
size: 'sm',
},
icon: {
outer: {
size: '8',
Expand All @@ -52,6 +76,9 @@ export const defaultConfig = {
},
md: {
size: '10',
font: {
size: 'sm',
},
icon: {
outer: {
size: '10',
Expand Down
Loading

0 comments on commit 11172f4

Please sign in to comment.