Skip to content

Commit

Permalink
feat(BaseSnack): update BaseSnack component configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
driss-chelouati committed Dec 17, 2023
1 parent 9e4eff4 commit 3581737
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 19 deletions.
4 changes: 4 additions & 0 deletions app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export default defineAppConfig({
BaseProse: {
rounded: 'md',
},
BaseSnack: {
size: 'md',
color: 'muted',
},
defaultShapes: {
accordion: 'rounded',
autocompleteItem: 'rounded',
Expand Down
66 changes: 47 additions & 19 deletions components/base/BaseSnack.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,85 @@
const props = withDefaults(
defineProps<{
/**
* The text to display in the snackbar.
* The size of the snack.
*
* @default 'md'
*/
label?: string
size?: 'xs' | 'sm' | 'md'
/**
* An optional icon to display in the snackbar.
* The color of snack.
*
* @default 'muted'
*/
icon?: string
color?: 'default' | 'muted'
/**
* An optional image to display in the snackbar.
* The text to display in the snackbar.
*/
image?: string
label?: string
/**
* The size of the snack.
* An optional icon to display in the snackbar.
*/
size?: 'sm' | 'md'
icon?: string
/**
* The color of snack, might be 'default' or 'muted'.
* An optional image to display in the snackbar.
*/
color?: 'default' | 'muted'
image?: string
}>(),
{
size: undefined,
color: undefined,
label: '',
icon: undefined,
image: undefined,
size: 'md',
color: 'default',
},
)
const emit = defineEmits<{
delete: []
}>()
const sizeStyle = {
const size = useNuiDefaultProperty(props, 'BaseSncak', 'size')
const color = useNuiDefaultProperty(props, 'BaseSncak', 'color')
const sizes = {
xs: 'nui-snack-sm',
sm: 'nui-snack-sm',
md: 'nui-snack-md',
}
const colorStyle = {
} as Record<string, string>
const colors = {
default: 'nui-snack-default',
muted: 'nui-snack-muted',
}
} as Record<string, string>
const closeSize = computed(() => {
switch (size.value) {
case 'xs': {
return 'xs'
}
case 'sm': {
return 'sm'
}
case 'md': {
return 'md'
}
default: {
return 'md'
}
}
})
</script>

<template>
<div
class="nui-snack"
:class="[
sizeStyle[props.size],
colorStyle[props.color],
size && sizes[size],
color && colors[color],
props.icon || props.image ? 'nui-has-media' : '',
]"
>
Expand All @@ -70,7 +97,8 @@ const colorStyle = {
</span>
<BaseButtonClose
class="nui-snack-button"
shape="full"
rounded="full"
:size="closeSize"
@click="emit('delete')"
/>
</div>
Expand Down
14 changes: 14 additions & 0 deletions nuxt.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,20 @@ export default defineNuxtSchema({
*/
rounded: 'none',
},
BaseSnack: {
/**
* The size of the snack.
*
* @type {'xs' | 'sm' | 'md'}
*/
size: 'md',
/**
* The color of the snack.
*
* @type {'default' | 'muted'}
*/
color: 'muted',
},
defaultShapes: {
/**
* Default shape for the BaseAccordion component
Expand Down

0 comments on commit 3581737

Please sign in to comment.