diff --git a/docs/components/content/examples/AlertExampleHtml.vue b/docs/components/content/examples/AlertExampleHtml.vue new file mode 100644 index 0000000000..69a69666db --- /dev/null +++ b/docs/components/content/examples/AlertExampleHtml.vue @@ -0,0 +1,11 @@ + diff --git a/docs/content/2.elements/5.accordion.md b/docs/content/2.elements/1.accordion.md similarity index 100% rename from docs/content/2.elements/5.accordion.md rename to docs/content/2.elements/1.accordion.md diff --git a/docs/content/2.elements/2.alert.md b/docs/content/2.elements/2.alert.md new file mode 100644 index 0000000000..19775fa41f --- /dev/null +++ b/docs/content/2.elements/2.alert.md @@ -0,0 +1,188 @@ +--- +description: Display an alert element to draw attention. +links: + - label: GitHub + icon: i-simple-icons-github + to: https://github.com/nuxtlabs/ui/blob/dev/src/runtime/components/elements/Alert.vue +navigation.badge: Edge +--- + +## Usage + +Pass a `title` to your Alert. + +::component-card +--- +props: + title: 'Heads up!' +--- +:: + +### Description + +You can add a `description` in addition of the `title`. + +::component-card +--- +baseProps: + title: 'Heads up!' +props: + description: 'You can add components to your app using the cli.' +--- +:: + +### Icon + +Use any icon from [Iconify](https://icones.js.org) by setting the `icon` prop by using this pattern: `i-{collection_name}-{icon_name}`. + +::component-card +--- +baseProps: + title: 'Heads up!' +props: + icon: 'i-heroicons-command-line' + description: 'You can add components to your app using the cli.' +excludedProps: + - icon +--- +:: + +### Avatar + +Use the [avatar](/elements/avatar) prop as an `object` and configure it with any of its props. + +::component-card +--- +baseProps: + title: 'Heads up!' +props: + description: 'You can add components to your app using the cli.' + avatar: + src: 'https://avatars.githubusercontent.com/u/739984?v=4' +excludedProps: + - avatar +--- +:: + +### Style + +Use the `color` and `variant` props to change the visual style of the Alert. + +- `color` can be any color from the `ui.colors` object or `white` (default). +- `variant` can be `solid` (default), `outline`, `soft` or `subtle`. + +::component-card +--- +baseProps: + title: 'Heads up!' + description: 'You can add components to your app using the cli.' +props: + icon: 'i-heroicons-command-line' + color: 'primary' + variant: 'solid' +extraColors: + - white +excludedProps: + - icon +--- +:: + +### Close + +Use the `close-button` prop to hide or customize the close button on the Alert. + +You can pass all the props of the [Button](/elements/button) component to customize it through the `close-button` prop or globally through `ui.alert.default.closeButton`. + +It defaults to `null` which means no close button will be displayed. A `close` event will be emitted when the close button is clicked. + +::component-card +--- +baseProps: + title: 'Heads up!' +props: + closeButton: + icon: 'i-heroicons-x-mark-20-solid' + color: 'gray' + variant: 'link' + padded: false +excludedProps: + - closeButton +--- +:: + +### Actions + +Use the `actions` prop to add actions to the Alert. + +Like for `closeButton`, you can pass all the props of the [Button](/elements/button) component plus a `click` function in the action but also customize the default style for the actions globally through `ui.alert.default.actionButton`. + +::component-card +--- +baseProps: + title: 'Heads up!' +props: + actions: + - label: Action 1 + - variant: 'ghost' + color: 'gray' + label: Action 2 +excludedProps: + - actions +--- +:: + +Actions will render differently whether you have a `description` set. + +::component-card +--- +baseProps: + title: 'Heads up!' + description: 'You can add components to your app using the cli.' +props: + actions: + - variant: 'solid' + color: 'primary' + label: Action 1 + - variant: 'outline' + color: 'primary' + label: Action 2 +excludedProps: + - actions +--- +:: + +## Slots + +### `title` / `description` + +Use the `#title` and `#description` slots to customize the Alert. + +This can be handy when you want to display HTML content. To achieve this, you can define those slots and use the `v-html` directive. + +::component-example +#default +:alert-example-html + +#code +```vue + +``` +:: + +## Props + +:component-props + +## Preset + +:component-preset diff --git a/docs/content/2.elements/1.avatar.md b/docs/content/2.elements/3.avatar.md similarity index 100% rename from docs/content/2.elements/1.avatar.md rename to docs/content/2.elements/3.avatar.md diff --git a/docs/content/2.elements/2.badge.md b/docs/content/2.elements/4.badge.md similarity index 100% rename from docs/content/2.elements/2.badge.md rename to docs/content/2.elements/4.badge.md diff --git a/docs/content/2.elements/3.button.md b/docs/content/2.elements/5.button.md similarity index 100% rename from docs/content/2.elements/3.button.md rename to docs/content/2.elements/5.button.md diff --git a/docs/content/2.elements/4.dropdown.md b/docs/content/2.elements/6.dropdown.md similarity index 100% rename from docs/content/2.elements/4.dropdown.md rename to docs/content/2.elements/6.dropdown.md diff --git a/docs/content/2.elements/6.icon.md b/docs/content/2.elements/7.icon.md similarity index 100% rename from docs/content/2.elements/6.icon.md rename to docs/content/2.elements/7.icon.md diff --git a/docs/content/2.elements/7.kbd.md b/docs/content/2.elements/8.kbd.md similarity index 100% rename from docs/content/2.elements/7.kbd.md rename to docs/content/2.elements/8.kbd.md diff --git a/docs/content/6.overlays/6.notification.md b/docs/content/6.overlays/6.notification.md index 63d7dfec55..ca4e9b7bb2 100644 --- a/docs/content/6.overlays/6.notification.md +++ b/docs/content/6.overlays/6.notification.md @@ -283,9 +283,7 @@ baseProps: timeout: 0 props: actions: - - variant: 'ghost' - color: 'gray' - label: Action 1 + - label: Action 1 - variant: 'solid' color: 'gray' label: Action 2 diff --git a/src/colors.ts b/src/colors.ts index 86e192c9fa..f40247896f 100644 --- a/src/colors.ts +++ b/src/colors.ts @@ -26,6 +26,24 @@ const kebabCase = (str: string) => { } const safelistByComponent = { + alert: (colorsAsRegex) => [{ + pattern: new RegExp(`bg-(${colorsAsRegex})-50`) + }, { + pattern: new RegExp(`bg-(${colorsAsRegex})-400`), + variants: ['dark'] + }, { + pattern: new RegExp(`bg-(${colorsAsRegex})-500`) + }, { + pattern: new RegExp(`text-(${colorsAsRegex})-400`), + variants: ['dark'] + }, { + pattern: new RegExp(`text-(${colorsAsRegex})-500`) + }, { + pattern: new RegExp(`ring-(${colorsAsRegex})-400`), + variants: ['dark'] + }, { + pattern: new RegExp(`ring-(${colorsAsRegex})-500`) + }], avatar: (colorsAsRegex) => [{ pattern: new RegExp(`bg-(${colorsAsRegex})-400`), variants: ['dark'] diff --git a/src/runtime/app.config.ts b/src/runtime/app.config.ts index 154a923102..81f57de726 100644 --- a/src/runtime/app.config.ts +++ b/src/runtime/app.config.ts @@ -291,6 +291,44 @@ const accordion = { } } +const alert = { + wrapper: 'w-full relative overflow-hidden', + title: 'text-sm font-medium', + description: 'mt-1 text-sm leading-4 opacity-90', + shadow: '', + rounded: 'rounded-lg', + padding: 'p-3', + icon: { + base: 'flex-shrink-0 w-5 h-5' + }, + avatar: { + base: 'flex-shrink-0 self-center', + size: 'md' + }, + color: { + white: { + solid: 'text-gray-900 dark:text-white bg-white dark:bg-gray-900 ring-1 ring-gray-200 dark:ring-gray-800' + } + }, + variant: { + solid: 'bg-{color}-500 dark:bg-{color}-400 text-white dark:text-gray-900', + outline: 'text-{color}-500 dark:text-{color}-400 ring-1 ring-inset ring-{color}-500 dark:ring-{color}-400', + soft: 'bg-{color}-50 dark:bg-{color}-400 dark:bg-opacity-10 text-{color}-500 dark:text-{color}-400', + subtle: 'bg-{color}-50 dark:bg-{color}-400 dark:bg-opacity-10 text-{color}-500 dark:text-{color}-400 ring-1 ring-inset ring-{color}-500 dark:ring-{color}-400 ring-opacity-25 dark:ring-opacity-25' + }, + default: { + color: 'white', + variant: 'solid', + icon: null, + closeButton: null, + actionButton: { + size: 'xs', + color: 'primary', + variant: 'link' + } + } +} + const kbd = { base: 'inline-flex items-center justify-center text-gray-900 dark:text-white', padding: 'px-1', @@ -942,7 +980,7 @@ const notification = { wrapper: 'w-full pointer-events-auto', container: 'relative overflow-hidden', title: 'text-sm font-medium text-gray-900 dark:text-white', - description: 'mt-1 text-sm leading-5 text-gray-500 dark:text-gray-400', + description: 'mt-1 text-sm leading-4 text-gray-500 dark:text-gray-400', background: 'bg-white dark:bg-gray-900', shadow: 'shadow-lg', rounded: 'rounded-lg', @@ -1003,6 +1041,7 @@ export default { dropdown, kbd, accordion, + alert, input, formGroup, textarea, diff --git a/src/runtime/components/elements/Alert.vue b/src/runtime/components/elements/Alert.vue new file mode 100644 index 0000000000..07960a7792 --- /dev/null +++ b/src/runtime/components/elements/Alert.vue @@ -0,0 +1,130 @@ + + + diff --git a/src/runtime/components/overlays/Notification.vue b/src/runtime/components/overlays/Notification.vue index da405c79d7..fbc4bcec10 100644 --- a/src/runtime/components/overlays/Notification.vue +++ b/src/runtime/components/overlays/Notification.vue @@ -3,7 +3,7 @@
-
+
@@ -13,18 +13,18 @@ {{ title }}

-

+

{{ description }}

-
+
-
+