Skip to content

Commit

Permalink
fix(components): move remaining classes to config (#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamincanac authored Nov 30, 2023
1 parent 5718dfd commit e408eab
Show file tree
Hide file tree
Showing 44 changed files with 196 additions and 117 deletions.
15 changes: 15 additions & 0 deletions docs/content/3.forms/1.input.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ excludedProps:
---
::

### Padded

Use the `padded` prop to remove the padding of the Input.

::component-card
---
props:
padded: false
baseProps:
placeholder: 'Search...'
variant: 'none'
class: 'w-full'
---
::

## Slots

### `leading`
Expand Down
15 changes: 15 additions & 0 deletions docs/content/3.forms/2.textarea.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ props:
---
::

### Padded

Use the `padded` prop to remove the padding of the Textarea.

::component-card
---
props:
padded: false
baseProps:
placeholder: 'Search...'
variant: 'none'
class: 'w-full'
---
::

## Props

:component-props
Expand Down
19 changes: 19 additions & 0 deletions docs/content/3.forms/3.select.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,25 @@ excludedProps:
---
::

### Padded

Use the `padded` prop to remove the padding of the Select.

::component-card
---
props:
padded: false
baseProps:
placeholder: 'Search...'
options:
- 'United States'
- 'Canada'
- 'Mexico'
variant: 'none'
class: 'w-full'
---
::

## Slots

### `leading`
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/elements/Alert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<UIcon v-if="icon" :name="icon" :class="ui.icon.base" />
<UAvatar v-if="avatar" v-bind="{ size: ui.avatar.size, ...avatar }" :class="ui.avatar.base" />

<div class="w-0 flex-1">
<div :class="ui.inner">
<p :class="ui.title">
<slot name="title" :title="title">
{{ title }}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/elements/AvatarGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineComponent({
default: () => ''
},
ui: {
type: Object as PropType<Partial<typeof avatarGroupConfig & { strategy?: Strategy }>>,
type: Object as PropType<Partial<typeof avatarGroupConfig> & { strategy?: Strategy }>,
default: () => ({})
}
},
Expand Down
10 changes: 6 additions & 4 deletions src/runtime/components/elements/Button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</slot>

<slot>
<span v-if="label" :class="[truncate ? 'text-left break-all line-clamp-1' : '']">
<span v-if="label" :class="[truncate ? ui.truncate : '']">
{{ label }}
</span>
</slot>
Expand Down Expand Up @@ -154,7 +154,7 @@ export default defineComponent({
ui.value.gap[size.value],
props.padded && ui.value[isSquare.value ? 'square' : 'padding'][size.value],
variant?.replaceAll('{color}', props.color),
props.block ? 'w-full flex justify-center items-center' : 'inline-flex items-center'
props.block ? ui.value.block : ui.value.inline
), props.class)
})
Expand All @@ -178,19 +178,21 @@ export default defineComponent({
return twJoin(
ui.value.icon.base,
ui.value.icon.size[size.value],
props.loading && 'animate-spin'
props.loading && ui.value.icon.loading
)
})
const trailingIconClass = computed(() => {
return twJoin(
ui.value.icon.base,
ui.value.icon.size[size.value],
props.loading && !isLeading.value && 'animate-spin'
props.loading && !isLeading.value && ui.value.icon.loading
)
})
return {
// eslint-disable-next-line vue/no-dupe-keys
ui,
attrs,
isLeading,
isTrailing,
Expand Down
17 changes: 2 additions & 15 deletions src/runtime/components/elements/ButtonGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default defineComponent({
default: () => ''
},
ui: {
type: Object as PropType<Partial<typeof buttonGroupConfig & { strategy?: Strategy }>>,
type: Object as PropType<Partial<typeof buttonGroupConfig> & { strategy?: Strategy }>,
default: () => ({})
}
},
Expand All @@ -52,20 +52,7 @@ export default defineComponent({
), props.class)
})

const rounded = computed(() => {
const roundedMap = {
'rounded-none': { horizontal: { start: 'rounded-s-none', end: 'rounded-e-none' }, vertical: { start: 'rounded-t-none', end: 'rounded-b-none' } },
'rounded-sm': { horizontal: { start: 'rounded-s-sm', end: 'rounded-e-sm' }, vertical: { start: 'rounded-t-sm', end: 'rounded-b-sm' } },
rounded: { horizontal: { start: 'rounded-s', end: 'rounded-e' }, vertical: { start: 'rounded-t', end: 'rounded-b' } },
'rounded-md': { horizontal: { start: 'rounded-s-md', end: 'rounded-e-md' }, vertical: { start: 'rounded-t-md', end: 'rounded-b-md' } },
'rounded-lg': { horizontal: { start: 'rounded-s-lg', end: 'rounded-e-lg' }, vertical: { start: 'rounded-t-lg', end: 'rounded-b-lg' } },
'rounded-xl': { horizontal: { start: 'rounded-s-xl', end: 'rounded-e-xl' }, vertical: { start: 'rounded-t-xl', end: 'rounded-b-xl' } },
'rounded-2xl': { horizontal: { start: 'rounded-s-2xl', end: 'rounded-e-2xl' }, vertical: { start: 'rounded-t-2xl', end: 'rounded-b-2xl' } },
'rounded-3xl': { horizontal: { start: 'rounded-s-3xl', end: 'rounded-e-3xl' }, vertical: { start: 'rounded-t-3xl', end: 'rounded-b-3xl' } },
'rounded-full': { horizontal: { start: 'rounded-s-full', end: 'rounded-e-full' }, vertical: { start: 'rounded-t-full', end: 'rounded-b-full' } }
}
return roundedMap[ui.value.rounded][props.orientation]
})
const rounded = computed(() => ui.value.orientation[ui.value.rounded][props.orientation])

useProvideButtonGroup({ orientation: toRef(props, 'orientation'), size: toRef(props, 'size'), ui, rounded })

Expand Down
6 changes: 3 additions & 3 deletions src/runtime/components/elements/Dropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
ref="trigger"
as="div"
:disabled="disabled"
class="inline-flex w-full"
:class="ui.trigger"
role="button"
@mouseover="onMouseOver"
>
Expand All @@ -18,7 +18,7 @@
<div v-if="open && items.length" ref="container" :class="[ui.container, ui.width]" :style="containerStyle" @mouseover="onMouseOver">
<Transition appear v-bind="ui.transition">
<div>
<div v-if="popper.arrow" data-popper-arrow :class="['invisible before:visible before:block before:rotate-45 before:z-[-1]', Object.values(ui.arrow)]" />
<div v-if="popper.arrow" data-popper-arrow :class="Object.values(ui.arrow)" />
<HMenuItems :class="[ui.base, ui.divide, ui.ring, ui.rounded, ui.shadow, ui.background, ui.height]" static>
<div v-for="(subItems, index) of items" :key="index" :class="ui.padding">
<NuxtLink v-for="(item, subIndex) of subItems" :key="subIndex" v-slot="{ href, target, rel, navigate, isExternal }" v-bind="omit(item, ['label', 'slot', 'icon', 'iconClass', 'avatar', 'shortcuts', 'disabled', 'click'])" custom>
Expand All @@ -35,7 +35,7 @@
<UIcon v-if="item.icon" :name="item.icon" :class="[ui.item.icon.base, active ? ui.item.icon.active : ui.item.icon.inactive, item.iconClass]" />
<UAvatar v-else-if="item.avatar" v-bind="{ size: ui.item.avatar.size, ...item.avatar }" :class="ui.item.avatar.base" />

<span class="truncate">{{ item.label }}</span>
<span :class="ui.item.label">{{ item.label }}</span>

<span v-if="item.shortcuts?.length" :class="ui.item.shortcuts">
<UKbd v-for="shortcut of item.shortcuts" :key="shortcut">{{ shortcut }}</UKbd>
Expand Down
22 changes: 4 additions & 18 deletions src/runtime/components/elements/MeterGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ export default defineComponent({
},
icon: {
type: String,
default: 'i-heroicons-minus'
default: () => meterGroupConfig.default.icon
},
class: {
type: [String, Object, Array] as PropType<any>,
default: () => ''
},
ui: {
type: Object as PropType<Partial<typeof meterGroupConfig & { strategy?: Strategy }>>,
type: Object as PropType<Partial<typeof meterGroupConfig> & { strategy?: Strategy }>,
default: () => ({})
}
},
Expand All @@ -70,21 +70,7 @@ export default defineComponent({

const children = computed(() => getSlotsChildren(slots))

const rounded = computed(() => {
const roundedMap = {
'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' }
}

return roundedMap[ui.value.rounded]
})
const rounded = computed(() => ui.value.orientation[ui.value.rounded])

function clampPercent (value: number, min: number, max: number): number {
if (min == max) {
Expand Down Expand Up @@ -198,7 +184,7 @@ export default defineComponent({
vNodeSlots[0] = slots.indicator({ percent: percent.value })
}

vNodeSlots[2] = h('ol', { class: 'list-disc list-inside' }, labels.value.map((label, key) => {
vNodeSlots[2] = h('ol', { class: ui.value.list }, labels.value.map((label, key) => {
const labelClass = computed(() => {
return twJoin(
uiMeter.value.label.base,
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/components/forms/Checkbox.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div :class="ui.wrapper">
<div class="flex items-center h-5">
<div :class="ui.container">
<input
:id="inputId"
v-model="toggle"
Expand All @@ -11,13 +11,12 @@
:checked="checked"
:indeterminate="indeterminate"
type="checkbox"
class="form-checkbox"
:class="inputClass"
v-bind="attrs"
@change="onChange"
>
</div>
<div v-if="label || $slots.label" class="ms-3 flex flex-col">
<div v-if="label || $slots.label" :class="ui.inner">
<label :for="inputId" :class="ui.label">
<slot name="label">{{ label }}</slot>
<span v-if="required" :class="ui.required">*</span>
Expand Down Expand Up @@ -130,6 +129,7 @@ export default defineComponent({
const inputClass = computed(() => {
return twMerge(twJoin(
ui.value.base,
ui.value.form,
ui.value.rounded,
ui.value.background,
ui.value.border,
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/components/forms/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
:required="required"
:placeholder="placeholder"
:disabled="disabled || loading"
class="form-input"
:class="inputClass"
v-bind="attrs"
@input="onInput"
Expand Down Expand Up @@ -234,6 +233,7 @@ export default defineComponent({
return twMerge(twJoin(
ui.value.base,
ui.value.form,
rounded.value,
ui.value.placeholder,
ui.value.size[size.value],
Expand Down Expand Up @@ -281,7 +281,7 @@ export default defineComponent({
ui.value.icon.base,
color.value && appConfig.ui.colors.includes(color.value) && ui.value.icon.color.replaceAll('{color}', color.value),
ui.value.icon.size[size.value],
props.loading && 'animate-spin'
props.loading && ui.value.icon.loading
)
})
Expand All @@ -298,7 +298,7 @@ export default defineComponent({
ui.value.icon.base,
color.value && appConfig.ui.colors.includes(color.value) && ui.value.icon.color.replaceAll('{color}', color.value),
ui.value.icon.size[size.value],
props.loading && !isLeading.value && 'animate-spin'
props.loading && !isLeading.value && ui.value.icon.loading
)
})
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/components/forms/Radio.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div :class="ui.wrapper">
<div class="flex items-center h-5">
<div :class="ui.container">
<input
:id="inputId"
v-model="pick"
Expand All @@ -9,12 +9,11 @@
:value="value"
:disabled="disabled"
type="radio"
class="form-radio"
:class="inputClass"
v-bind="attrs"
>
</div>
<div v-if="label || $slots.label" class="ms-3 flex flex-col">
<div v-if="label || $slots.label" :class="ui.inner">
<label :for="inputId" :class="ui.label">
<slot name="label">{{ label }}</slot>
<span v-if="required" :class="ui.required">*</span>
Expand Down Expand Up @@ -128,6 +127,7 @@ export default defineComponent({
const inputClass = computed(() => {
return twMerge(twJoin(
ui.value.base,
ui.value.form,
ui.value.background,
ui.value.border,
color.value && ui.value.ring.replaceAll('{color}', color.value),
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/forms/RadioGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default defineComponent({
default: () => ({})
},
uiRadio: {
type: Object as PropType<Partial<typeof configRadio & { strategy?: Strategy }>>,
type: Object as PropType<Partial<typeof configRadio> & { strategy?: Strategy }>,
default: () => ({})
}
},
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/components/forms/Select.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
:value="modelValue"
:required="required"
:disabled="disabled || loading"
class="form-select"
:class="selectClass"
v-bind="attrs"
@input="onInput"
Expand Down Expand Up @@ -256,6 +255,7 @@ export default defineComponent({
return twMerge(twJoin(
ui.value.base,
ui.value.form,
rounded.value,
ui.value.size[size.value],
props.padded ? ui.value.padding[size.value] : 'p-0',
Expand Down Expand Up @@ -302,7 +302,7 @@ export default defineComponent({
ui.value.icon.base,
color.value && appConfig.ui.colors.includes(color.value) && ui.value.icon.color.replaceAll('{color}', color.value),
ui.value.icon.size[size.value],
props.loading && 'animate-spin'
props.loading && ui.value.icon.loading
)
})
Expand All @@ -319,7 +319,7 @@ export default defineComponent({
ui.value.icon.base,
color.value && appConfig.ui.colors.includes(color.value) && ui.value.icon.color.replaceAll('{color}', color.value),
ui.value.icon.size[size.value],
props.loading && !isLeading.value && 'animate-spin'
props.loading && !isLeading.value && ui.value.icon.loading
)
})
Expand Down
Loading

1 comment on commit e408eab

@vercel
Copy link

@vercel vercel bot commented on e408eab Nov 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-git-dev-nuxt-js.vercel.app
ui-nuxt-js.vercel.app
ui.nuxt.com

Please sign in to comment.