Skip to content

Commit

Permalink
feat(Divider): handle size prop (#1307)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
  • Loading branch information
adjabaev and benjamincanac committed Feb 7, 2024
1 parent a506cbb commit cbeede6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
8 changes: 2 additions & 6 deletions docs/content/2.components/divider.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,15 @@ excludedProps:

### Size

You can change the size of the divider by using the `ui` prop
Use the `size` prop to change the size of the divider.

::component-card
---
props:
label: Nuxt UI
ui:
border:
size:
horizontal: border-t-2
size: sm
excludedProps:
- label
- ui
---
::

Expand Down
11 changes: 9 additions & 2 deletions src/runtime/components/layout/Divider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import UIcon from '../elements/Icon.vue'
import UAvatar from '../elements/Avatar.vue'
import { useUI } from '../../composables/useUI'
import { mergeConfig } from '../../utils'
import type { Avatar, Strategy } from '../../types'
import type { Avatar, DividerSize, Strategy } from '../../types'
// @ts-expect-error
import appConfig from '#build/app.config'
import { divider } from '#ui/ui.config'
Expand All @@ -52,6 +52,13 @@ export default defineComponent({
type: Object as PropType<Avatar>,
default: null
},
size: {
type: String as PropType<DividerSize>,
default: () => config.default.size,
validator (value: string) {
return Object.keys(config.border.size.horizontal).includes(value) || Object.keys(config.border.size.vertical).includes(value)
}
},
orientation: {
type: String as PropType<'horizontal' | 'vertical'>,
default: 'horizontal',
Expand Down Expand Up @@ -92,7 +99,7 @@ export default defineComponent({
return twJoin(
ui.value.border.base,
ui.value.border[props.orientation],
ui.value.border.size[props.orientation],
ui.value.border.size[props.orientation][props.size],
ui.value.border.type[props.type]
)
})
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/types/divider.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { divider } from '#ui/ui.config'

export type DividerSize = keyof typeof divider.border.size.horizontal | keyof typeof divider.border.size.vertical
1 change: 1 addition & 0 deletions src/runtime/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export * from './button'
export * from './chip'
export * from './clipboard'
export * from './command-palette'
export * from './divider'
export * from './dropdown'
export * from './form-group'
export * from './form'
Expand Down
23 changes: 20 additions & 3 deletions src/runtime/ui.config/layout/divider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,22 @@ export default {
horizontal: 'w-full',
vertical: 'h-full',
size: {
horizontal: 'border-t',
vertical: 'border-s'
horizontal: {
'2xs': 'border-t',
xs: 'border-t-[2px]',
sm: 'border-t-[3px]',
md: 'border-t-[4px]',
lg: 'border-t-[5px]',
xl: 'border-t-[6px]'
},
vertical: {
'2xs': 'border-s',
xs: 'border-s-[2px]',
sm: 'border-s-[3px]',
md: 'border-s-[4px]',
lg: 'border-s-[5px]',
xl: 'border-s-[6px]'
}
},
type: {
solid: 'border-solid',
Expand All @@ -30,5 +44,8 @@ export default {
base: 'flex-shrink-0',
size: '2xs' as const
},
label: 'text-sm'
label: 'text-sm',
default: {
size: '2xs' as const
}
}

0 comments on commit cbeede6

Please sign in to comment.