From b3bc6e2e9e9446ee3dab7ae02f939a9c01c4218b Mon Sep 17 00:00:00 2001 From: Eduard Aymerich Date: Wed, 6 Sep 2023 17:41:31 +0200 Subject: [PATCH] feat(ButtonGroup): add `orientation` prop (#603) Co-authored-by: Benjamin Canac --- docs/components/content/ComponentCard.vue | 2 +- docs/content/2.elements/5.button.md | 5 +++ .../components/elements/ButtonGroup.ts | 42 +++++++++++++------ 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/docs/components/content/ComponentCard.vue b/docs/components/content/ComponentCard.vue index f515f216..9d3837f4 100644 --- a/docs/components/content/ComponentCard.vue +++ b/docs/components/content/ComponentCard.vue @@ -11,7 +11,7 @@ class="justify-center" /> diff --git a/src/runtime/components/elements/ButtonGroup.ts b/src/runtime/components/elements/ButtonGroup.ts index 142d0811..928061a3 100644 --- a/src/runtime/components/elements/ButtonGroup.ts +++ b/src/runtime/components/elements/ButtonGroup.ts @@ -20,6 +20,13 @@ export default defineComponent({ return Object.keys(appConfig.ui.button.size).includes(value) } }, + orientation: { + type: String as PropType<'horizontal' | 'vertical'>, + default: 'horizontal', + validator (value: string) { + return ['horizontal', 'vertical'].includes(value) + } + }, ui: { type: Object as PropType>, default: () => ({}) @@ -33,21 +40,30 @@ export default defineComponent({ const children = computed(() => getSlotsChildren(slots)) - const rounded = computed(() => ({ - 'rounded-none': { left: 'rounded-s-none', right: 'rounded-e-none' }, - 'rounded-sm': { left: 'rounded-s-sm', right: 'rounded-e-sm' }, - rounded: { left: 'rounded-s', right: 'rounded-e' }, - 'rounded-md': { left: 'rounded-s-md', right: 'rounded-e-md' }, - 'rounded-lg': { left: 'rounded-s-lg', right: 'rounded-e-lg' }, - 'rounded-xl': { left: 'rounded-s-xl', right: 'rounded-e-xl' }, - 'rounded-2xl': { left: 'rounded-s-2xl', right: 'rounded-e-2xl' }, - 'rounded-3xl': { left: 'rounded-s-3xl', right: 'rounded-e-3xl' }, - 'rounded-full': { left: 'rounded-s-full', right: 'rounded-e-full' } - }[ui.value.rounded])) + const rounded = computed(() => { + const roundedMap = { + 'rounded-none': { horizontal: { left: 'rounded-s-none', right: 'rounded-e-none' }, vertical: { top: 'rounded-t-none', bottom: 'rounded-b-none' } }, + 'rounded-sm': { horizontal: { left: 'rounded-s-sm', right: 'rounded-e-sm' }, vertical: { top: 'rounded-t-sm', bottom: 'rounded-b-sm' } }, + rounded: { horizontal: { left: 'rounded-s', right: 'rounded-e' }, vertical: { top: 'rounded-t', bottom: 'rounded-b' } }, + 'rounded-md': { horizontal: { left: 'rounded-s-md', right: 'rounded-e-md' }, vertical: { top: 'rounded-t-md', bottom: 'rounded-b-md' } }, + 'rounded-lg': { horizontal: { left: 'rounded-s-lg', right: 'rounded-e-lg' }, vertical: { top: 'rounded-t-lg', bottom: 'rounded-b-lg' } }, + 'rounded-xl': { horizontal: { left: 'rounded-s-xl', right: 'rounded-e-xl' }, vertical: { top: 'rounded-t-xl', bottom: 'rounded-b-xl' } }, + 'rounded-2xl': { horizontal: { left: 'rounded-s-2xl', right: 'rounded-e-2xl' }, vertical: { top: 'rounded-t-2xl', bottom: 'rounded-b-2xl' } }, + 'rounded-3xl': { horizontal: { left: 'rounded-s-3xl', right: 'rounded-e-3xl' }, vertical: { top: 'rounded-t-3xl', bottom: 'rounded-b-3xl' } }, + 'rounded-full': { horizontal: { left: 'rounded-s-full', right: 'rounded-e-full' }, vertical: { top: 'rounded-t-full', bottom: 'rounded-b-full' } } + } + return roundedMap[ui.value.rounded][props.orientation] + }) const clones = computed(() => children.value.map((node, index) => { const vProps: any = {} + if (props.orientation === 'vertical') { + ui.value.wrapper = 'flex flex-col -space-y-px' + } else { + ui.value.wrapper = 'inline-flex -space-x-px' + } + if (props.size) { vProps.size = props.size } @@ -57,11 +73,11 @@ export default defineComponent({ vProps.ui.base = '!shadow-none' if (index === 0) { - vProps.ui.rounded += ` ${rounded.value.left}` + vProps.ui.rounded += ` ${rounded.value.left || rounded.value.top}` } if (index === children.value.length - 1) { - vProps.ui.rounded += ` ${rounded.value.right}` + vProps.ui.rounded += ` ${rounded.value.right || rounded.value.bottom}` } return cloneVNode(node, vProps)