diff --git a/docs/components/content/examples/ChipExampleContentSlot.vue b/docs/components/content/examples/ChipExampleContentSlot.vue new file mode 100644 index 0000000000..7ebcb94b0b --- /dev/null +++ b/docs/components/content/examples/ChipExampleContentSlot.vue @@ -0,0 +1,19 @@ + diff --git a/docs/components/content/examples/ChipExampleShow.vue b/docs/components/content/examples/ChipExampleShow.vue new file mode 100644 index 0000000000..e1712d6578 --- /dev/null +++ b/docs/components/content/examples/ChipExampleShow.vue @@ -0,0 +1,19 @@ + + + diff --git a/docs/content/2.elements/12.chip.md b/docs/content/2.elements/12.chip.md new file mode 100644 index 0000000000..cb40612459 --- /dev/null +++ b/docs/content/2.elements/12.chip.md @@ -0,0 +1,134 @@ +--- +description: Display a chip indicator on any component. +navigation: + badge: New +links: + - label: GitHub + icon: i-simple-icons-github + to: https://github.com/nuxt/ui/blob/dev/src/runtime/components/elements/Chip.vue +--- + +## Usage + +Wrap any component with the `Chip` component to display a chip indicator. + +::component-card +--- +code: >- + + +--- + +#default +:u-button{icon="i-heroicons-inbox" color="gray"} +:: + +### Size + +Use the `size` prop to change the size of the chip. + +::component-card +--- +props: + size: '2xl' +code: >- + + +--- + +#default +:u-button{icon="i-heroicons-inbox" color="gray"} +:: + +### Color + +Use the `color` prop to change the color of the chip. + +::component-card +--- +props: + color: 'red' +code: >- + + +--- + +#default +:u-button{icon="i-heroicons-inbox" color="gray"} +:: + +### Position + +Use the `position` prop to change the position of the chip. + +::component-card +--- +props: + position: 'bottom-right' +code: >- + + +--- + +#default +:u-button{icon="i-heroicons-inbox" color="gray"} +:: + +### Text + +Use the `text` prop to display text in the chip. + +::component-card +--- +props: + text: '3' + size: '2xl' +excludedProps: + - size +code: >- + + +--- + +#default +:u-button{icon="i-heroicons-inbox" color="gray"} +:: + +### Show + +Use the `show` prop to conditionally display the chip. + +:component-example{component="chip-example-show"} + +### Inset + +Use the `inset` prop to display the chip inside the component. This is useful when dealing with rounded components. + +::component-card +--- +props: + inset: true +code: >- + + +--- + +#default +:u-avatar{src="https://avatars.githubusercontent.com/u/739984?v=4" alt="Avatar"} +:: + +## Slots + +### `content` + +Use the `#content` slot to fully customize the chip. + +:component-example{component="chip-example-content-slot"} + +## Props + +:component-props + +## Config + +:component-preset diff --git a/src/colors.ts b/src/colors.ts index 2e853d5615..b866d24ba8 100644 --- a/src/colors.ts +++ b/src/colors.ts @@ -198,6 +198,12 @@ const safelistByComponent = { variants: ['dark'] }, { pattern: new RegExp(`text-(${colorsAsRegex})-500`) + }], + chip: (colorsAsRegex) => [{ + pattern: new RegExp(`bg-(${colorsAsRegex})-400`), + variants: ['dark'] + }, { + pattern: new RegExp(`bg-(${colorsAsRegex})-500`) }] } diff --git a/src/runtime/components/elements/Chip.vue b/src/runtime/components/elements/Chip.vue new file mode 100644 index 0000000000..3b10d4048a --- /dev/null +++ b/src/runtime/components/elements/Chip.vue @@ -0,0 +1,92 @@ + + + diff --git a/src/runtime/types/chip.d.ts b/src/runtime/types/chip.d.ts new file mode 100644 index 0000000000..1f13938a11 --- /dev/null +++ b/src/runtime/types/chip.d.ts @@ -0,0 +1,11 @@ +import { chip } from '../ui.config' +import colors from '#ui-colors' + +export type ChipSize = keyof typeof chip.size +export type ChipColor = 'gray' | typeof colors[number] +export type ChipPosition = keyof typeof chip.position + +export interface Chip { + color?: ChipColor + position?: ChipPosition +} diff --git a/src/runtime/types/index.d.ts b/src/runtime/types/index.d.ts index e76895a79d..519d296317 100644 --- a/src/runtime/types/index.d.ts +++ b/src/runtime/types/index.d.ts @@ -4,6 +4,7 @@ export * from './avatar' export * from './badge' export * from './breadcrumb' export * from './button' +export * from './chip' export * from './clipboard' export * from './command-palette' export * from './dropdown' diff --git a/src/runtime/ui.config.ts b/src/runtime/ui.config.ts index 1fac6cd84b..6073e747fa 100644 --- a/src/runtime/ui.config.ts +++ b/src/runtime/ui.config.ts @@ -257,6 +257,41 @@ export const buttonGroup = { shadow: 'shadow-sm' } +export const chip = { + wrapper: 'relative inline-flex items-center justify-center flex-shrink-0', + base: 'absolute rounded-full ring-1 ring-white dark:ring-gray-900 flex items-center justify-center text-white dark:text-gray-900 font-medium whitespace-nowrap', + background: 'bg-{color}-500 dark:bg-{color}-400', + position: { + 'top-right': 'top-0 right-0', + 'bottom-right': 'bottom-0 right-0', + 'top-left': 'top-0 left-0', + 'bottom-left': 'bottom-0 left-0' + }, + translate: { + 'top-right': '-translate-y-1/2 translate-x-1/2 transform', + 'bottom-right': 'translate-y-1/2 translate-x-1/2 transform', + 'top-left': '-translate-y-1/2 -translate-x-1/2 transform', + 'bottom-left': 'translate-y-1/2 -translate-x-1/2 transform' + }, + size: { + '3xs': 'h-[4px] min-w-[4px] text-[4px] p-px', + '2xs': 'h-[5px] min-w-[5px] text-[5px] p-px', + xs: 'h-1.5 min-w-[0.375rem] text-[6px] p-px', + sm: 'h-2 min-w-[0.5rem] text-[7px] p-0.5', + md: 'h-2.5 min-w-[0.625rem] text-[8px] p-0.5', + lg: 'h-3 min-w-[0.75rem] text-[10px] p-0.5', + xl: 'h-3.5 min-w-[0.875rem] text-[11px] p-1', + '2xl': 'h-4 min-w-[1rem] text-[12px] p-1', + '3xl': 'h-5 min-w-[1.25rem] text-[14px] p-1' + }, + default: { + size: 'sm', + color: 'primary', + position: 'top-right', + inset: false + } +} + export const dropdown = { wrapper: 'relative inline-flex text-left rtl:text-right', container: 'z-20 group',