@volverjs/ui-vue 0.0.6-beta.2 → 0.0.6-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,7 +17,7 @@
17
17
  })
18
18
 
19
19
  const avatarItems = computed(() => {
20
- return items.value.slice(0, toShow.value).map((item, index) => {
20
+ return items.value.slice(0, toShow.value).map((item) => {
21
21
  let modifiers: string[] = []
22
22
  let itemModifiers: string[] = []
23
23
 
@@ -35,7 +35,7 @@
35
35
 
36
36
  return {
37
37
  ...item,
38
- key: item.key || `${index}_${new Date().getTime()}`,
38
+ key: item.key || useUniqueId().value,
39
39
  modifiers: [...modifiers, ...itemModifiers],
40
40
  }
41
41
  })
@@ -0,0 +1,56 @@
1
+ <script setup lang="ts">
2
+ import { VvNavProps, VvNavEvents, type NavItem } from '@/components/VvNav'
3
+ import VvAction from '@/components/VvAction/VvAction.vue'
4
+
5
+ const props = defineProps(VvNavProps)
6
+ const emit = defineEmits(VvNavEvents)
7
+ const { modifiers } = toRefs(props)
8
+ const activeItem: Ref<string | null> = ref(null)
9
+
10
+ // bem css classes
11
+ const bemCssClasses = useModifiers('vv-nav', modifiers)
12
+
13
+ /**
14
+ * Triggers when the item is clicked.
15
+ * @private
16
+ * @event click
17
+ * @param [NavItem, number] item, id - the clicked item
18
+ */
19
+ function onClick(item: NavItem, id: string) {
20
+ if (!item.disabled) {
21
+ emit('click', item)
22
+ activeItem.value = id
23
+ }
24
+ }
25
+ </script>
26
+
27
+ <template>
28
+ <nav :class="bemCssClasses">
29
+ <ul class="vv-nav__menu" role="menu" aria-busy="true">
30
+ <li
31
+ v-for="(navItem, index) in items"
32
+ :key="`nav-item_${index}`"
33
+ class="vv-nav__item"
34
+ role="presentation"
35
+ >
36
+ <VvAction
37
+ v-bind="{
38
+ disabled: navItem.disabled,
39
+ to: navItem.to,
40
+ href: navItem.href,
41
+ tabindex: 0,
42
+ }"
43
+ :class="{
44
+ current: activeItem == `nav-item_${index}`,
45
+ disabled: navItem.disabled,
46
+ }"
47
+ class="vv-nav__item-label"
48
+ v-on="navItem.on || {}"
49
+ @click="onClick(navItem, `nav-item_${index}`)"
50
+ >
51
+ {{ navItem.title }}
52
+ </VvAction>
53
+ </li>
54
+ </ul>
55
+ </nav>
56
+ </template>
@@ -0,0 +1,20 @@
1
+ import { ModifiersProps } from '@/props'
2
+
3
+ export type NavItem = {
4
+ title: string
5
+ to?: string | { [key: string]: unknown }
6
+ href?: string
7
+ disabled?: boolean
8
+ on: () => void
9
+ }
10
+
11
+ export const VvNavProps = {
12
+ ...ModifiersProps,
13
+ items: {
14
+ type: Array<NavItem>,
15
+ required: true,
16
+ default: () => [],
17
+ },
18
+ }
19
+
20
+ export const VvNavEvents = ['click']
@@ -0,0 +1,11 @@
1
+ <script setup lang="ts">
2
+ defineProps({
3
+ title: String,
4
+ })
5
+ </script>
6
+
7
+ <template>
8
+ <span class="vv-nav__heading-label" aria-hidden="true">
9
+ {{ title }}
10
+ </span>
11
+ </template>
@@ -0,0 +1,8 @@
1
+ export default defineComponent({
2
+ render() {
3
+ return h('li', {
4
+ class: 'vv-nav__divider',
5
+ role: 'separator',
6
+ })
7
+ },
8
+ })
@@ -0,0 +1,34 @@
1
+ import { VvNavProps } from '@/components/VvNav'
2
+ import { ModifiersArgTypes } from '@/stories/argTypes'
3
+
4
+ export const defaultArgs = {
5
+ ...propsToObject(VvNavProps),
6
+ items: [
7
+ {
8
+ title: 'Item 1',
9
+ href: 'javascript:void(0)',
10
+ },
11
+ {
12
+ title: 'Item 2',
13
+ to: 'about',
14
+ },
15
+ {
16
+ title: 'Item 3',
17
+ to: 'contacts',
18
+ on: {
19
+ click: () => {
20
+ // eslint-disable-next-line no-console
21
+ console.log('clicked Item 3')
22
+ },
23
+ },
24
+ },
25
+ ],
26
+ modifiers: 'sidebar',
27
+ }
28
+
29
+ export const argTypes = {
30
+ modifiers: {
31
+ ...ModifiersArgTypes.modifiers,
32
+ options: ['sidebar', 'aside', 'tabs', 'full'],
33
+ },
34
+ }
@@ -0,0 +1,28 @@
1
+ import { Meta, Story, Canvas } from '@storybook/addon-docs'
2
+ import VvNav from '@/components/VvNav/VvNav.vue'
3
+ import { defaultArgs, argTypes } from './Nav.settings'
4
+ import { defaultTest } from './Nav.test'
5
+
6
+ <Meta
7
+ title="Components/Nav"
8
+ component={VvNav}
9
+ args={defaultArgs}
10
+ argTypes={argTypes}
11
+ />
12
+
13
+ export const Template = (args) => ({
14
+ components: { VvNav },
15
+ setup() {
16
+ return { args }
17
+ },
18
+ template: /* html */ `
19
+ <div class="m-md w-1/5">
20
+ <vv-nav v-bind="args" data-testId="element" />
21
+ </div>`,
22
+ })
23
+
24
+ <Canvas>
25
+ <Story name="Default" play={defaultTest}>
26
+ {Template.bind()}
27
+ </Story>
28
+ </Canvas>
@@ -0,0 +1,32 @@
1
+ import type { PlayAttributes } from '@/test/types'
2
+ import { expect } from '@/test/expect'
3
+ import { within, userEvent } from '@storybook/testing-library'
4
+
5
+ export async function defaultTest({ canvasElement, args }: PlayAttributes) {
6
+ const element = (await within(canvasElement).findByTestId(
7
+ 'element',
8
+ )) as HTMLElement
9
+
10
+ if (!args.items || !args.items?.length) {
11
+ throw new Error('No items passed')
12
+ }
13
+
14
+ // check children number the same of items prop
15
+ expect(element.children?.[0].children.length).toEqual(args.items?.length)
16
+
17
+ // take firse and second elements
18
+ const firstEl = await element.getElementsByTagName('a')?.[0]
19
+ const secondEl = await element.getElementsByTagName('router-link')?.[1]
20
+ // check they have not current class
21
+ const secondElHasCurrentClass = secondEl.classList.contains('current')
22
+ const firstElHasCurrentClass = firstEl.classList.contains('current')
23
+
24
+ await expect(firstElHasCurrentClass).toBe(false)
25
+ await expect(secondElHasCurrentClass).toBe(false)
26
+ // click first item and check "current" css class
27
+ await userEvent.click(firstEl)
28
+ await expect(firstEl).toHaveClass('current')
29
+
30
+ // check accessibility
31
+ await expect(element).toHaveNoViolations()
32
+ }
@@ -0,0 +1,48 @@
1
+ import { Meta, Story, Canvas } from '@storybook/addon-docs'
2
+ import VvNav from '@/components/VvNav/VvNav.vue'
3
+ import { defaultArgs, argTypes } from './Nav.settings'
4
+ import { defaultTest } from './Nav.test'
5
+ import { Template } from './Nav.stories.mdx'
6
+
7
+ <Meta
8
+ title="Components/Nav/Modifiers"
9
+ component={VvNav}
10
+ args={defaultArgs}
11
+ argTypes={argTypes}
12
+ />
13
+
14
+ <Canvas>
15
+ <Story name="Sidebar" play={defaultTest} args={{ modifiers: 'sidebar' }}>
16
+ {Template.bind({})}
17
+ </Story>
18
+ </Canvas>
19
+
20
+ <Canvas>
21
+ <Story name="Aside" play={defaultTest} args={{ modifiers: 'aside' }}>
22
+ {Template.bind({})}
23
+ </Story>
24
+ </Canvas>
25
+
26
+ <Canvas>
27
+ <Story
28
+ name="Tabs"
29
+ play={defaultTest}
30
+ args={{
31
+ modifiers: 'tabs',
32
+ }}
33
+ >
34
+ {Template.bind({})}
35
+ </Story>
36
+ </Canvas>
37
+
38
+ <Canvas>
39
+ <Story
40
+ name="TabsFull"
41
+ play={defaultTest}
42
+ args={{
43
+ modifiers: 'tabs full',
44
+ }}
45
+ >
46
+ {Template.bind({})}
47
+ </Story>
48
+ </Canvas>