-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
- Loading branch information
1 parent
6cc77a3
commit d4f1b5e
Showing
8 changed files
with
317 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
docs/components/content/examples/ChipExampleContentSlot.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<template> | ||
<UChip size="md" position="bottom-right" inset :ui="{ base: '-mx-2 rounded-none ring-0', background: '' }"> | ||
<UAvatar | ||
src="https://avatars.githubusercontent.com/u/739984?v=4" | ||
alt="Avatar" | ||
size="lg" | ||
/> | ||
|
||
<template #content> | ||
<UAvatar | ||
src="https://avatars.githubusercontent.com/in/80442?v=4" | ||
alt="Avatar" | ||
size="xs" | ||
:ui="{ rounded: 'rounded-md' }" | ||
class="shadow-md" | ||
/> | ||
</template> | ||
</UChip> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script setup> | ||
const items = [{ | ||
name: 'messages', | ||
icon: 'i-heroicons-chat-bubble-oval-left', | ||
count: 3 | ||
}, { | ||
name: 'notifications', | ||
icon: 'i-heroicons-bell', | ||
count: 0 | ||
}] | ||
</script> | ||
|
||
<template> | ||
<div class="flex gap-3"> | ||
<UChip v-for="{ name, icon, count } in items" :key="name" :show="count > 0"> | ||
<UButton :icon="icon" color="gray" /> | ||
</UChip> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: >- | ||
|
||
<UButton icon="i-heroicons-inbox" color="gray" /> | ||
--- | ||
|
||
#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: >- | ||
|
||
<UButton icon="i-heroicons-inbox" color="gray" /> | ||
--- | ||
|
||
#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: >- | ||
|
||
<UButton icon="i-heroicons-inbox" color="gray" /> | ||
--- | ||
|
||
#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: >- | ||
|
||
<UButton icon="i-heroicons-inbox" color="gray" /> | ||
--- | ||
|
||
#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: >- | ||
|
||
<UButton icon="i-heroicons-inbox" color="gray" /> | ||
--- | ||
|
||
#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: >- | ||
|
||
<UAvatar src="https://avatars.githubusercontent.com/u/739984?v=4" alt="Avatar" /> | ||
--- | ||
|
||
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<template> | ||
<div :class="ui.wrapper" v-bind="attrs"> | ||
<slot /> | ||
|
||
<span v-if="show" :class="chipClass"> | ||
<slot name="content"> | ||
{{ text }} | ||
</slot> | ||
</span> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, computed, toRef } from 'vue' | ||
import type { PropType } from 'vue' | ||
import { twJoin } from 'tailwind-merge' | ||
import { useUI } from '../../composables/useUI' | ||
import { mergeConfig } from '../../utils' | ||
import type { ChipSize, ChipColor, ChipPosition, Strategy } from '../../types' | ||
// @ts-expect-error | ||
import appConfig from '#build/app.config' | ||
import { chip } from '#ui/ui.config' | ||
const config = mergeConfig<typeof chip>(appConfig.ui.strategy, appConfig.ui.chip, chip) | ||
export default defineComponent({ | ||
inheritAttrs: false, | ||
props: { | ||
size: { | ||
type: String as PropType<ChipSize>, | ||
default: () => config.default.size, | ||
validator (value: string) { | ||
return Object.keys(config.size).includes(value) | ||
} | ||
}, | ||
color: { | ||
type: String as PropType<ChipColor>, | ||
default: () => config.default.color, | ||
validator (value: string) { | ||
return ['gray', ...appConfig.ui.colors].includes(value) | ||
} | ||
}, | ||
position: { | ||
type: String as PropType<ChipPosition>, | ||
default: () => config.default.position, | ||
validator (value: string) { | ||
return Object.keys(config.position).includes(value) | ||
} | ||
}, | ||
text: { | ||
type: [String, Number], | ||
default: null | ||
}, | ||
inset: { | ||
type: Boolean, | ||
default: () => config.default.inset | ||
}, | ||
show: { | ||
type: Boolean, | ||
default: true | ||
}, | ||
class: { | ||
type: [String, Object, Array] as PropType<any>, | ||
default: undefined | ||
}, | ||
ui: { | ||
type: Object as PropType<Partial<typeof config & { strategy?: Strategy }>>, | ||
default: undefined | ||
} | ||
}, | ||
setup (props) { | ||
const { ui, attrs } = useUI('chip', toRef(props, 'ui'), config, toRef(props, 'class')) | ||
const chipClass = computed(() => { | ||
return twJoin( | ||
ui.value.base, | ||
ui.value.size[props.size], | ||
ui.value.position[props.position], | ||
props.inset ? null : ui.value.translate[props.position], | ||
ui.value.background.replaceAll('{color}', props.color) | ||
) | ||
}) | ||
return { | ||
// eslint-disable-next-line vue/no-dupe-keys | ||
ui, | ||
attrs, | ||
chipClass | ||
} | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d4f1b5e
There was a problem hiding this comment.
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.com
ui-nuxt-js.vercel.app