diff --git a/docs/components/content/examples/HorizontalNavigationExample.vue b/docs/components/content/examples/HorizontalNavigationExample.vue new file mode 100644 index 0000000000..dbc0f8f82b --- /dev/null +++ b/docs/components/content/examples/HorizontalNavigationExample.vue @@ -0,0 +1,27 @@ + + + diff --git a/docs/components/content/examples/HorizontalNavigationExampleDefaultSlot.vue b/docs/components/content/examples/HorizontalNavigationExampleDefaultSlot.vue new file mode 100644 index 0000000000..fac158721d --- /dev/null +++ b/docs/components/content/examples/HorizontalNavigationExampleDefaultSlot.vue @@ -0,0 +1,22 @@ + + + diff --git a/docs/components/content/examples/HorizontalNavigationExampleSections.vue b/docs/components/content/examples/HorizontalNavigationExampleSections.vue new file mode 100644 index 0000000000..e702cf5b6c --- /dev/null +++ b/docs/components/content/examples/HorizontalNavigationExampleSections.vue @@ -0,0 +1,29 @@ + + + diff --git a/docs/components/content/examples/VerticalNavigationExample.vue b/docs/components/content/examples/VerticalNavigationExample.vue index b75b5a070d..7b5bd7c092 100644 --- a/docs/components/content/examples/VerticalNavigationExample.vue +++ b/docs/components/content/examples/VerticalNavigationExample.vue @@ -1,4 +1,6 @@ diff --git a/docs/content/5.navigation/1.vertical-navigation.md b/docs/content/5.navigation/1.vertical-navigation.md index ca4908702a..a2c5d7364b 100644 --- a/docs/content/5.navigation/1.vertical-navigation.md +++ b/docs/content/5.navigation/1.vertical-navigation.md @@ -1,6 +1,6 @@ --- title: VerticalNavigation -description: Display a vertical navigation. +description: Display a list of vertical links. links: - label: GitHub icon: i-simple-icons-github diff --git a/docs/content/5.navigation/6.horizontal-navigation.md b/docs/content/5.navigation/6.horizontal-navigation.md new file mode 100644 index 0000000000..27a3df5e36 --- /dev/null +++ b/docs/content/5.navigation/6.horizontal-navigation.md @@ -0,0 +1,64 @@ +--- +title: HorizontalNavigation +description: Display a list of horizontal links. +links: + - label: GitHub + icon: i-simple-icons-github + to: https://github.com/nuxt/ui/blob/dev/src/runtime/components/navigation/HorizontalNavigation.vue +navigation: + badge: New +--- + +## Usage + +Pass an array to the `links` prop of the HorizontalNavigation component. Each link can have the following properties: + +- `label` - The label of the link. +- `labelClass` - The class of the link label. +- `icon` - The icon of the link. +- `iconClass` - The class of the link icon. +- `avatar` - The avatar of the link. You can pass all the props of the [Avatar](/elements/avatar) component. +- `badge` - A badge to display next to the label. You can pass all the props of the [Badge](/elements/badge) component. +- `click` - The click handler of the link. + +You can also pass any property from the [NuxtLink](https://nuxt.com/docs/api/components/nuxt-link#props) component such as `to`, `exact`, etc. + +:component-example{component="horizontal-navigation-example"} + +## Sections + +Group your navigation links into distinct sections, they will be displayed apart thanks to a `justify-between` flexbox layout. + +You can do this by passing an array of arrays to the `links` prop of the HorizontalNavigation component. + +:component-example{component="horizontal-navigation-example-sections"} + +## Slots + +You can use slots to customize links display. + +### `default` + +Use the `#default` slot to customize the link label. You will have access to the `link` and `isActive` properties in the slot scope. + +:component-example{component="horizontal-navigation-example-default-slot"} + +### `avatar` + +Use the `#avatar` slot to customize the link avatar. You will have access to the `link` and `isActive` properties in the slot scope. + +### `icon` + +Use the `#icon` slot to customize the link icon. You will have access to the `link` and `isActive` properties in the slot scope. + +### `badge` + +Use the `#badge` slot to customize the link badge. You will have access to the `link` and `isActive` properties in the slot scope. + +## Props + +:component-props + +## Config + +:component-preset diff --git a/src/runtime/components/navigation/HorizontalNavigation.vue b/src/runtime/components/navigation/HorizontalNavigation.vue new file mode 100644 index 0000000000..0d59b69c74 --- /dev/null +++ b/src/runtime/components/navigation/HorizontalNavigation.vue @@ -0,0 +1,109 @@ + + + diff --git a/src/runtime/types/horizontal-navigation.d.ts b/src/runtime/types/horizontal-navigation.d.ts new file mode 100644 index 0000000000..ac50b2ee2d --- /dev/null +++ b/src/runtime/types/horizontal-navigation.d.ts @@ -0,0 +1,13 @@ +import type { Link } from './link' +import type { Avatar } from './avatar' +import type { Badge } from './badge' + +export interface HorizontalNavigationLink extends Link { + label: string + labelClass?: string + icon?: string + iconClass?: string + avatar?: Avatar + click?: Function + badge?: string | number | Badge +} diff --git a/src/runtime/types/index.d.ts b/src/runtime/types/index.d.ts index 908ca6bdca..9ede63bfd4 100644 --- a/src/runtime/types/index.d.ts +++ b/src/runtime/types/index.d.ts @@ -10,6 +10,7 @@ export * from './command-palette' export * from './dropdown' export * from './form-group' export * from './form' +export * from './horizontal-navigation' export * from './input' export * from './kbd' export * from './link' diff --git a/src/runtime/ui.config/index.ts b/src/runtime/ui.config/index.ts index 4255a09642..ed9dc639d3 100644 --- a/src/runtime/ui.config/index.ts +++ b/src/runtime/ui.config/index.ts @@ -38,6 +38,7 @@ export { default as divider } from './layout/divider' // Navigation export { default as verticalNavigation } from './navigation/verticalNavigation' +export { default as horizontalNavigation } from './navigation/horizontalNavigation' export { default as commandPalette } from './navigation/commandPalette' export { default as pagination } from './navigation/pagination' export { default as tabs } from './navigation/tabs' diff --git a/src/runtime/ui.config/navigation/horizontalNavigation.ts b/src/runtime/ui.config/navigation/horizontalNavigation.ts new file mode 100644 index 0000000000..3f87ddd37c --- /dev/null +++ b/src/runtime/ui.config/navigation/horizontalNavigation.ts @@ -0,0 +1,25 @@ +export default { + wrapper: 'relative w-full flex items-center justify-between', + container: 'flex items-center', + base: 'group relative w-full flex items-center gap-1.5 px-2.5 py-3.5 rounded-md font-medium text-sm focus:outline-none focus-visible:outline-none dark:focus-visible:outline-none focus-visible:ring-inset focus-visible:ring-2 focus-visible:ring-primary-500 dark:focus-visible:ring-primary-400 disabled:cursor-not-allowed disabled:opacity-75', + before: 'before:absolute before:inset-x-0 before:inset-y-2 before:inset-px before:rounded-md hover:before:bg-gray-50 dark:hover:before:bg-gray-800/50', + after: 'after:absolute after:bottom-0 after:inset-x-2.5 after:block after:h-[2px] after:mt-2', + active: 'text-gray-900 dark:text-white after:bg-primary-500 dark:after:bg-primary-400 after:rounded-full', + inactive: 'text-gray-500 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white', + label: 'truncate relative', + icon: { + base: 'flex-shrink-0 w-5 h-5', + active: 'text-gray-700 dark:text-gray-200', + inactive: 'text-gray-400 dark:text-gray-500 group-hover:text-gray-700 dark:group-hover:text-gray-200' + }, + avatar: { + base: 'flex-shrink-0', + size: '2xs' as const + }, + badge: { + base: 'flex-shrink-0 ml-auto relative rounded', + color: 'gray' as const, + variant: 'solid' as const, + size: 'xs' as const + } +}