Skip to content

Commit

Permalink
feat(BaseDropdown): update BaseDropdown component configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
driss-chelouati committed Dec 17, 2023
1 parent 423e719 commit 23fdd57
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 38 deletions.
9 changes: 8 additions & 1 deletion app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ export default defineAppConfig({
},
BaseCard: {
rounded: 'sm',
color: 'default',
color: 'white',
},
BaseDropdown: {
variant: 'button',
buttonColor: 'default',
color: 'white',
rounded: 'sm',
size: 'md',
},
defaultShapes: {
accordion: 'rounded',
Expand Down
103 changes: 66 additions & 37 deletions components/base/BaseDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import { Float } from '@headlessui-float/vue'
const props = withDefaults(
defineProps<{
/**
* The flavor of the dropdown.
* The variant of the dropdown.
*
* @since 2.0.0
* @default 'button'
*/
flavor?: 'button' | 'context' | 'text'
variant?: 'button' | 'context' | 'text'
/**
* The color of the button.
*
* @default 'default'
*/
buttonColor?:
| 'default'
Expand All @@ -25,6 +30,8 @@ const props = withDefaults(
/**
* The color of the dropdown.
*
* @default 'white'
*/
color?:
| 'white'
Expand All @@ -39,20 +46,19 @@ const props = withDefaults(
| 'none'
/**
* The shape of the dropdown.
* The radius of the dropdown button.
*
* @since 2.0.0
* @default 'sm'
*/
shape?: 'straight' | 'rounded' | 'smooth' | 'curved' | 'full'
rounded?: 'none' | 'sm' | 'md' | 'lg' | 'full'
/**
* The orientation of the dropdown.
*
* @deprecated use placement instead
*/
orientation?: 'start' | 'end'
/**
* Used a fixed strategy to float the component
*/
fixed?: boolean
/**
* The placement of the dropdown via floating-ui.
Expand All @@ -73,6 +79,8 @@ const props = withDefaults(
/**
* The size of the dropdown.
*
* @default 'md'
*/
size?: 'md' | 'lg'
Expand All @@ -85,38 +93,59 @@ const props = withDefaults(
* The header label to display for the dropdown.
*/
headerLabel?: string
/**
* Used a fixed strategy to float the component
*/
fixed?: boolean
}>(),
{
flavor: 'button',
buttonColor: 'default',
shape: undefined,
orientation: 'start',
variant: undefined,
buttonColor: undefined,
color: undefined,
rounded: undefined,
orientation: undefined,
placement: undefined,
size: 'md',
color: 'white',
size: undefined,
label: '',
headerLabel: undefined,
fixed: false,
},
)
const appConfig = useAppConfig()
const shape = computed(
() => props.shape ?? appConfig.nui.defaultShapes?.dropdown,
)
const variant = useNuiDefaultProperty(props, 'BaseDropdown', 'variant')
const buttonColor = useNuiDefaultProperty(props, 'BaseDropdown', 'buttonColor')
const color = useNuiDefaultProperty(props, 'BaseDropdown', 'color')
const rounded = useNuiDefaultProperty(props, 'BaseDropdown', 'rounded')
const size = useNuiDefaultProperty(props, 'BaseDropdown', 'size')
const orientation = useNuiDefaultProperty(props, 'BaseDropdown', 'orientation')
const sizeStyle = {
const sizes = {
md: 'nui-menu-md',
lg: 'nui-menu-lg',
}
const shapeStyle = {
straight: '',
rounded: 'nui-menu-rounded',
smooth: 'nui-menu-smooth',
curved: 'nui-menu-curved',
} as Record<string, string>
const radiuses = {
none: '',
sm: 'nui-menu-rounded',
md: 'nui-menu-smooth',
lg: 'nui-menu-curved',
full: 'nui-menu-curved',
}
const colorStyle = {
} as Record<string, string>
const buttonColors = {
none: '',
default: 'nui-button-default',
primary: 'nui-button-primary',
info: 'nui-button-info',
success: 'nui-button-success',
warning: 'nui-button-warning',
danger: 'nui-button-danger',
light: 'nui-button-light',
muted: 'nui-button-muted',
} as Record<string, string>
const colors = {
white: 'nui-menu-white',
'white-contrast': 'nui-menu-white-contrast',
muted: 'nui-menu-muted',
Expand All @@ -127,7 +156,7 @@ const colorStyle = {
warning: 'nui-menu-warning',
danger: 'nui-menu-danger',
none: '',
}
} as Record<string, string>
/**
* fallback placement with old orientation value
Expand Down Expand Up @@ -157,7 +186,7 @@ const placementValue = computed(() => {
leave-from="transform scale-100 opacity-100"
leave-to="transform scale-95 opacity-0"
flip
:offset="props.flavor === 'context' ? 6 : 4"
:offset="props.variant === 'context' ? 6 : 4"
:strategy="props.fixed ? 'fixed' : 'absolute'"
:placement="placementValue"
:adaptive-width="props.fixed"
Expand All @@ -166,9 +195,9 @@ const placementValue = computed(() => {
<MenuButton as="template">
<slot name="button" v-bind="{ open, close }">
<BaseButton
v-if="props.flavor === 'button'"
:color="props.buttonColor"
:shape="shape"
v-if="variant === 'button' || props.variant === 'button'"
:color="props.buttonColor ? props.buttonColor : buttonColor"
:rounded="props.rounded ? props.rounded : rounded"
class="!pe-3 !ps-4"
>
<slot name="label" v-bind="{ open, close }">
Expand All @@ -181,7 +210,7 @@ const placementValue = computed(() => {
/>
</BaseButton>
<button
v-else-if="props.flavor === 'context'"
v-else-if="props.variant === 'context'"
type="button"
class="nui-context-button nui-focus"
>
Expand All @@ -194,7 +223,7 @@ const placementValue = computed(() => {
</span>
</button>
<button
v-else-if="props.flavor === 'text'"
v-else-if="props.variant === 'text'"
type="button"
class="nui-text-button nui-focus"
>
Expand All @@ -214,9 +243,9 @@ const placementValue = computed(() => {
<MenuItems
class="nui-dropdown-menu"
:class="[
shape && shapeStyle[shape],
sizeStyle[props.size],
colorStyle[props.color],
size && sizes[size],
rounded && radiuses[rounded],
color && colors[color],
]"
>
<div v-if="props.headerLabel" class="nui-menu-header">
Expand Down
56 changes: 56 additions & 0 deletions nuxt.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,62 @@ export default defineNuxtSchema({
*/
color: 'white',
},
BaseDropdown: {
/**
* The variant of the dropdown.
*
* @type {'button' | 'context' | 'text'}
*/
variant: 'button',
/**
* The color of the dropdown button.
*
* @type {'default' | 'primary' | 'info' | 'success' | 'warning' | 'danger' | 'light' | 'muted' | 'none'}
*/
buttonColor: 'default',
/**
* The color of the dropdown.
*
* @type {'white' | 'white-contrast' | 'muted' | 'muted-contrast' | 'primary' | 'info' | 'success' | 'warning' | 'danger' | 'none'}
*/
color: 'white',
/**
* Default rounded for the BaseDropdown component
*
* @type {'none' | 'sm' | 'md' | 'lg' | 'full'}
*/
rounded: 'md',
/**
* The placement of the dropdown via floating-ui
*
* @type {'top' | 'top-start' | 'top-end' | 'right' | 'right-start' | 'right-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end'}
*/
placement: undefined,
/**
* Default size for the BaseDropdown component menu
*
* @type {'md' | 'lg'}
*/
size: 'md',
/**
* The label to display for the dropdown.
*
* @type {string}
*/
label: '',
/**
* The header label to display for the dropdown.
*
* @type {string}
*/
headerLabel: undefined,
/**
* Used a fixed strategy to float the component
*
* @type {boolean}
*/
fixed: false,
},
defaultShapes: {
/**
* Default shape for the BaseAccordion component
Expand Down

0 comments on commit 23fdd57

Please sign in to comment.