@papillonarts/components 0.9.0 → 0.11.0
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.
- package/build/index.js +12 -0
- package/build/primer/Alert/Alert.js +122 -0
- package/build/primer/Alert/Alert.prop.js +19 -0
- package/build/primer/Alert/index.js +19 -0
- package/build/primer/Blankslate/Blankslate.js +30 -0
- package/build/primer/Blankslate/Blankslate.prop.js +18 -0
- package/build/primer/Blankslate/index.js +19 -0
- package/build/primer/Breadcrumb/Breadcrumb.js +75 -0
- package/build/primer/Breadcrumb/Breadcrumb.prop.js +14 -0
- package/build/primer/Breadcrumb/index.js +19 -0
- package/build/primer/Button/Button.js +108 -0
- package/build/primer/Button/Button.prop.js +48 -0
- package/build/primer/Button/index.js +49 -0
- package/build/primer/Dropdown/Dropdown.js +102 -0
- package/build/primer/Dropdown/Dropdown.prop.js +18 -0
- package/build/primer/Dropdown/index.js +19 -0
- package/build/primer/ErrorBoundary/ErrorBoundary.js +59 -0
- package/build/primer/ErrorBoundary/ErrorBoundary.prop.js +7 -0
- package/build/primer/ErrorBoundary/index.js +12 -0
- package/build/primer/Form/Checkbox/Checkbox.js +48 -0
- package/build/primer/Form/Checkbox/Checkbox.prop.js +22 -0
- package/build/primer/Form/Checkbox/index.js +19 -0
- package/build/primer/Form/Input/Input.js +55 -0
- package/build/primer/Form/Input/Input.prop.js +27 -0
- package/build/primer/Form/Input/index.js +25 -0
- package/build/primer/Form/Radio/Radio.js +47 -0
- package/build/primer/Form/Radio/Radio.prop.js +22 -0
- package/build/primer/Form/Radio/index.js +19 -0
- package/build/primer/Form/index.js +24 -0
- package/build/primer/Grid/DisplayTable/DisplayTable.js +57 -0
- package/build/primer/Grid/DisplayTable/DisplayTable.prop.js +11 -0
- package/build/primer/Grid/DisplayTable/index.js +12 -0
- package/build/primer/Grid/FlexGrid/FlexGrid.js +249 -0
- package/build/primer/Grid/FlexGrid/FlexGrid.prop.js +28 -0
- package/build/primer/Grid/FlexGrid/index.js +25 -0
- package/build/primer/Grid/index.js +14 -0
- package/build/primer/Icon/Icon.js +70 -0
- package/build/primer/Icon/Icon.part.js +1295 -0
- package/build/primer/Icon/Icon.prop.js +678 -0
- package/build/primer/Icon/index.js +25 -0
- package/build/primer/Label/Label.js +30 -0
- package/build/primer/Label/Label.prop.js +26 -0
- package/build/primer/Label/index.js +12 -0
- package/build/primer/Loader/Loader.js +64 -0
- package/build/primer/Loader/Loader.prop.js +15 -0
- package/build/primer/Loader/index.js +19 -0
- package/build/primer/Navigation/Menu/Menu.js +69 -0
- package/build/primer/Navigation/Menu/Menu.prop.js +10 -0
- package/build/primer/Navigation/Menu/index.js +12 -0
- package/build/primer/Navigation/TabNav/TabNav.js +124 -0
- package/build/primer/Navigation/TabNav/TabNav.prop.js +16 -0
- package/build/primer/Navigation/TabNav/index.js +19 -0
- package/build/primer/Navigation/UnderlineNav/UnderlineNav.js +122 -0
- package/build/primer/Navigation/UnderlineNav/UnderlineNav.prop.js +20 -0
- package/build/primer/Navigation/UnderlineNav/index.js +25 -0
- package/build/primer/Navigation/index.js +17 -0
- package/build/primer/Pagination/PreviousNext/PreviousNext.js +84 -0
- package/build/primer/Pagination/PreviousNext/PreviousNext.prop.js +30 -0
- package/build/primer/Pagination/PreviousNext/index.js +19 -0
- package/build/primer/Pagination/index.js +11 -0
- package/build/primer/Popover/Popover.js +63 -0
- package/build/primer/Popover/Popover.prop.js +29 -0
- package/build/primer/Popover/index.js +25 -0
- package/build/primer/Progress/Progress.js +30 -0
- package/build/primer/Progress/Progress.prop.js +15 -0
- package/build/primer/Progress/index.js +19 -0
- package/build/primer/Select/Select.js +67 -0
- package/build/primer/Select/Select.prop.js +15 -0
- package/build/primer/Select/index.js +19 -0
- package/build/primer/SelectMenu/SelectMenu.js +94 -0
- package/build/primer/SelectMenu/SelectMenu.prop.js +10 -0
- package/build/primer/SelectMenu/index.js +12 -0
- package/build/primer/Subhead/Subhead.js +26 -0
- package/build/primer/Subhead/Subhead.prop.js +10 -0
- package/build/primer/Subhead/index.js +12 -0
- package/build/primer/Toast/Toast.js +54 -0
- package/build/primer/Toast/Toast.prop.js +18 -0
- package/build/primer/Toast/index.js +19 -0
- package/build/primer/index.js +87 -0
- package/package.json +5 -5
- package/build/index.ts +0 -1
- package/build/primer/Alert/Alert.prop.ts +0 -45
- package/build/primer/Alert/Alert.tsx +0 -101
- package/build/primer/Alert/__tests__/Alert.int.story.tsx +0 -86
- package/build/primer/Alert/__tests__/Alert.int.test.ts +0 -37
- package/build/primer/Alert/index.ts +0 -2
- package/build/primer/Blankslate/Blankslate.prop.ts +0 -26
- package/build/primer/Blankslate/Blankslate.tsx +0 -26
- package/build/primer/Blankslate/__tests__/Blankslate.int.story.tsx +0 -43
- package/build/primer/Blankslate/__tests__/Blankslate.int.test.ts +0 -29
- package/build/primer/Blankslate/index.ts +0 -2
- package/build/primer/Breadcrumb/Breadcrumb.prop.ts +0 -28
- package/build/primer/Breadcrumb/Breadcrumb.tsx +0 -57
- package/build/primer/Breadcrumb/__tests__/Breadcrumb.int.story.tsx +0 -40
- package/build/primer/Breadcrumb/__tests__/Breadcrumb.int.test.ts +0 -40
- package/build/primer/Breadcrumb/index.ts +0 -2
- package/build/primer/Button/Button.prop.ts +0 -77
- package/build/primer/Button/Button.tsx +0 -91
- package/build/primer/Button/__tests__/Button.int.story.tsx +0 -173
- package/build/primer/Button/__tests__/Button.int.test.ts +0 -191
- package/build/primer/Button/index.ts +0 -2
- package/build/primer/Dropdown/Dropdown.prop.ts +0 -33
- package/build/primer/Dropdown/Dropdown.tsx +0 -102
- package/build/primer/Dropdown/__tests__/Dropdown.int.story.tsx +0 -43
- package/build/primer/Dropdown/__tests__/Dropdown.int.test.ts +0 -53
- package/build/primer/Dropdown/index.ts +0 -2
- package/build/primer/ErrorBoundary/ErrorBoundary.prop.ts +0 -5
- package/build/primer/ErrorBoundary/ErrorBoundary.tsx +0 -35
- package/build/primer/ErrorBoundary/__tests__/ErrorBoundary.int.story.tsx +0 -23
- package/build/primer/ErrorBoundary/__tests__/ErrorBoundary.int.test.ts +0 -9
- package/build/primer/ErrorBoundary/index.ts +0 -1
- package/build/primer/Form/Checkbox/Checkbox.prop.ts +0 -34
- package/build/primer/Form/Checkbox/Checkbox.tsx +0 -40
- package/build/primer/Form/Checkbox/__tests__/Checkbox.int.story.tsx +0 -50
- package/build/primer/Form/Checkbox/__tests__/Checkbox.int.test.ts +0 -23
- package/build/primer/Form/Checkbox/index.ts +0 -2
- package/build/primer/Form/Input/Input.prop.ts +0 -43
- package/build/primer/Form/Input/Input.tsx +0 -43
- package/build/primer/Form/Input/__tests__/Input.int.story.tsx +0 -54
- package/build/primer/Form/Input/__tests__/Input.int.test.ts +0 -15
- package/build/primer/Form/Input/index.ts +0 -2
- package/build/primer/Form/Radio/Radio.prop.ts +0 -30
- package/build/primer/Form/Radio/Radio.tsx +0 -38
- package/build/primer/Form/Radio/__tests__/Radio.int.story.tsx +0 -42
- package/build/primer/Form/Radio/__tests__/Radio.int.test.ts +0 -13
- package/build/primer/Form/Radio/index.ts +0 -2
- package/build/primer/Form/index.ts +0 -19
- package/build/primer/Grid/DisplayTable/DisplayTable.prop.ts +0 -21
- package/build/primer/Grid/DisplayTable/DisplayTable.tsx +0 -68
- package/build/primer/Grid/DisplayTable/__tests__/DisplayTable.int.data.ts +0 -289
- package/build/primer/Grid/DisplayTable/__tests__/DisplayTable.int.story.tsx +0 -27
- package/build/primer/Grid/DisplayTable/__tests__/DisplayTable.int.test.ts +0 -9
- package/build/primer/Grid/DisplayTable/index.ts +0 -1
- package/build/primer/Grid/FlexGrid/FlexGrid.prop.ts +0 -59
- package/build/primer/Grid/FlexGrid/FlexGrid.tsx +0 -274
- package/build/primer/Grid/FlexGrid/__tests__/FlexGrid.int.data.ts +0 -289
- package/build/primer/Grid/FlexGrid/__tests__/FlexGrid.int.story.tsx +0 -146
- package/build/primer/Grid/FlexGrid/__tests__/FlexGrid.int.test.ts +0 -46
- package/build/primer/Grid/FlexGrid/index.ts +0 -2
- package/build/primer/Grid/index.ts +0 -9
- package/build/primer/Icon/Icon.part.ts +0 -1289
- package/build/primer/Icon/Icon.prop.ts +0 -1337
- package/build/primer/Icon/Icon.tsx +0 -49
- package/build/primer/Icon/__tests__/Icon.int.story.tsx +0 -58
- package/build/primer/Icon/__tests__/Icon.int.test.ts +0 -13
- package/build/primer/Icon/index.ts +0 -2
- package/build/primer/Label/Label.prop.ts +0 -31
- package/build/primer/Label/Label.tsx +0 -27
- package/build/primer/Label/__tests__/Label.int.story.tsx +0 -19
- package/build/primer/Label/__tests__/Label.int.test.ts +0 -9
- package/build/primer/Label/index.ts +0 -1
- package/build/primer/Loader/Loader.prop.ts +0 -16
- package/build/primer/Loader/Loader.tsx +0 -43
- package/build/primer/Loader/__tests__/Loader.int.story.tsx +0 -34
- package/build/primer/Loader/__tests__/Loader.int.test.ts +0 -21
- package/build/primer/Loader/index.ts +0 -2
- package/build/primer/Navigation/Menu/Menu.prop.ts +0 -26
- package/build/primer/Navigation/Menu/Menu.tsx +0 -42
- package/build/primer/Navigation/Menu/__tests__/Menu.int.story.tsx +0 -55
- package/build/primer/Navigation/Menu/__tests__/Menu.int.test.ts +0 -57
- package/build/primer/Navigation/Menu/index.ts +0 -1
- package/build/primer/Navigation/TabNav/TabNav.prop.ts +0 -39
- package/build/primer/Navigation/TabNav/TabNav.tsx +0 -105
- package/build/primer/Navigation/TabNav/__tests__/TabNav.int.story.tsx +0 -168
- package/build/primer/Navigation/TabNav/__tests__/TabNav.int.test.ts +0 -55
- package/build/primer/Navigation/TabNav/index.ts +0 -2
- package/build/primer/Navigation/UnderlineNav/UnderlineNav.prop.ts +0 -41
- package/build/primer/Navigation/UnderlineNav/UnderlineNav.tsx +0 -106
- package/build/primer/Navigation/UnderlineNav/__tests__/UnderlineNav.int.story.tsx +0 -140
- package/build/primer/Navigation/UnderlineNav/__tests__/UnderlineNav.int.test.ts +0 -81
- package/build/primer/Navigation/UnderlineNav/index.ts +0 -2
- package/build/primer/Navigation/index.ts +0 -12
- package/build/primer/Pagination/PreviousNext/PreviousNext.prop.ts +0 -53
- package/build/primer/Pagination/PreviousNext/PreviousNext.tsx +0 -71
- package/build/primer/Pagination/PreviousNext/__tests__/PreviousNext.int.story.tsx +0 -48
- package/build/primer/Pagination/PreviousNext/__tests__/PreviousNext.int.test.ts +0 -15
- package/build/primer/Pagination/PreviousNext/index.ts +0 -2
- package/build/primer/Pagination/index.ts +0 -6
- package/build/primer/Popover/Popover.prop.ts +0 -49
- package/build/primer/Popover/Popover.tsx +0 -80
- package/build/primer/Popover/__tests__/Popover.int.story.tsx +0 -216
- package/build/primer/Popover/__tests__/Popover.int.test.ts +0 -71
- package/build/primer/Popover/index.ts +0 -2
- package/build/primer/Progress/Progress.prop.ts +0 -16
- package/build/primer/Progress/Progress.tsx +0 -19
- package/build/primer/Progress/__tests__/Progress.int.story.tsx +0 -28
- package/build/primer/Progress/__tests__/Progress.int.test.ts +0 -17
- package/build/primer/Progress/index.ts +0 -2
- package/build/primer/Select/Select.prop.ts +0 -24
- package/build/primer/Select/Select.tsx +0 -58
- package/build/primer/Select/__tests__/Select.int.story.tsx +0 -38
- package/build/primer/Select/__tests__/Select.int.test.ts +0 -42
- package/build/primer/Select/index.ts +0 -2
- package/build/primer/SelectMenu/SelectMenu.prop.ts +0 -25
- package/build/primer/SelectMenu/SelectMenu.tsx +0 -68
- package/build/primer/SelectMenu/__tests__/SelectMenu.int.story.tsx +0 -50
- package/build/primer/SelectMenu/__tests__/SelectMenu.int.test.ts +0 -56
- package/build/primer/SelectMenu/index.ts +0 -1
- package/build/primer/Subhead/Subhead.prop.ts +0 -10
- package/build/primer/Subhead/Subhead.tsx +0 -15
- package/build/primer/Subhead/__tests__/Subhead.int.story.tsx +0 -23
- package/build/primer/Subhead/__tests__/Subhead.int.test.ts +0 -13
- package/build/primer/Subhead/index.ts +0 -1
- package/build/primer/Toast/Toast.prop.ts +0 -21
- package/build/primer/Toast/Toast.tsx +0 -38
- package/build/primer/Toast/__tests__/Toast.int.story.tsx +0 -50
- package/build/primer/Toast/__tests__/Toast.int.test.ts +0 -25
- package/build/primer/Toast/index.ts +0 -2
- package/build/primer/index.ts +0 -83
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import cx from 'classnames'
|
|
2
|
-
import { v1 as uuidv1 } from 'uuid'
|
|
3
|
-
import { action } from 'storybook/actions'
|
|
4
|
-
import { withTests } from '@storybook/addon-jest'
|
|
5
|
-
import { BrowserRouter, Link } from 'react-router-dom'
|
|
6
|
-
import layoutStyles from '@papillonarts/css/build/primer/utilities/layout.scss'
|
|
7
|
-
import tabNavStyles from '../TabNav.scss'
|
|
8
|
-
import buttonStyles from '../../../Button/Button.scss'
|
|
9
|
-
import { tabNavState } from '../TabNav.prop'
|
|
10
|
-
import results from '../../../../../../../.jest-test-results.json'
|
|
11
|
-
|
|
12
|
-
const TabNav =
|
|
13
|
-
process.env.NODE_ENV === 'develop' || process.env.NODE_ENV === 'test'
|
|
14
|
-
? require('../../../../index').primer.Navigation.TabNav
|
|
15
|
-
: require('../../../../../build').primer.Navigation.TabNav
|
|
16
|
-
|
|
17
|
-
export default {
|
|
18
|
-
title: 'Primer/Molecule/Navigation/TabNav',
|
|
19
|
-
component: TabNav,
|
|
20
|
-
decorators: [withTests({ results })],
|
|
21
|
-
parameters: { jest: ['TabNav.int.test.js'] },
|
|
22
|
-
excludeStories: ['ariaAttr', 'defaultItems', 'navigationItems', 'mixedEnabledVisibleItems', 'custom'],
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const ariaAttr = {
|
|
26
|
-
label: 'Foo bar',
|
|
27
|
-
current: 'page',
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const defaultItems = [
|
|
31
|
-
{
|
|
32
|
-
href: '#url',
|
|
33
|
-
text: 'Foo tab',
|
|
34
|
-
isSelected: true,
|
|
35
|
-
enabled: true,
|
|
36
|
-
visible: true,
|
|
37
|
-
},
|
|
38
|
-
{ href: '#url', text: 'Bar tab', isSelected: false, enabled: true, visible: true },
|
|
39
|
-
]
|
|
40
|
-
|
|
41
|
-
export const navigationItems = [
|
|
42
|
-
{
|
|
43
|
-
link: {
|
|
44
|
-
component: Link,
|
|
45
|
-
props: { ...{ to: '/foo' } },
|
|
46
|
-
children: 'Foo link',
|
|
47
|
-
},
|
|
48
|
-
isSelected: true,
|
|
49
|
-
enabled: true,
|
|
50
|
-
visible: true,
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
link: {
|
|
54
|
-
component: Link,
|
|
55
|
-
props: { ...{ to: '/bar' } },
|
|
56
|
-
children: 'Bar link',
|
|
57
|
-
},
|
|
58
|
-
isSelected: false,
|
|
59
|
-
enabled: true,
|
|
60
|
-
visible: true,
|
|
61
|
-
},
|
|
62
|
-
]
|
|
63
|
-
|
|
64
|
-
export const mixedEnabledVisibleItems = [
|
|
65
|
-
{
|
|
66
|
-
link: {
|
|
67
|
-
component: Link,
|
|
68
|
-
props: { ...{ to: '/foo' } },
|
|
69
|
-
children: 'Foo link',
|
|
70
|
-
},
|
|
71
|
-
isSelected: true,
|
|
72
|
-
enabled: true,
|
|
73
|
-
visible: true,
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
link: {
|
|
77
|
-
component: Link,
|
|
78
|
-
props: { ...{ to: '/bar' } },
|
|
79
|
-
children: 'Bar link',
|
|
80
|
-
},
|
|
81
|
-
isSelected: false,
|
|
82
|
-
enabled: false,
|
|
83
|
-
visible: true,
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
link: {
|
|
87
|
-
component: Link,
|
|
88
|
-
props: { ...{ to: '/disco' } },
|
|
89
|
-
children: 'Disco link',
|
|
90
|
-
},
|
|
91
|
-
isSelected: false,
|
|
92
|
-
enabled: false,
|
|
93
|
-
visible: false,
|
|
94
|
-
},
|
|
95
|
-
]
|
|
96
|
-
|
|
97
|
-
const actionButton = (
|
|
98
|
-
<a key={uuidv1()} className={cx(buttonStyles.btn, buttonStyles['btn-sm'], layoutStyles['float-right'])} href="#url" role="button">
|
|
99
|
-
Button
|
|
100
|
-
</a>
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
const buttonActions = [actionButton]
|
|
104
|
-
|
|
105
|
-
const actionText = (
|
|
106
|
-
<div key={uuidv1()} className={cx(tabNavStyles['tabnav-extra'], layoutStyles['float-right'])}>
|
|
107
|
-
Tabnav widget text here.
|
|
108
|
-
</div>
|
|
109
|
-
)
|
|
110
|
-
|
|
111
|
-
const textActions = [actionText]
|
|
112
|
-
|
|
113
|
-
const actionLink = (
|
|
114
|
-
<div key={uuidv1()} className={layoutStyles['float-right']}>
|
|
115
|
-
<a className={tabNavStyles['tabnav-extra']} href="#url">
|
|
116
|
-
Tabnav extra link
|
|
117
|
-
</a>
|
|
118
|
-
<a className={tabNavStyles['tabnav-extra']} href="#url">
|
|
119
|
-
Tabnav extra link
|
|
120
|
-
</a>
|
|
121
|
-
</div>
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
const linkActions = [actionLink]
|
|
125
|
-
|
|
126
|
-
export function custom(items, onClick) {
|
|
127
|
-
return (
|
|
128
|
-
<BrowserRouter>
|
|
129
|
-
<TabNav ariaAttr={ariaAttr} items={items} onClick={onClick} />
|
|
130
|
-
</BrowserRouter>
|
|
131
|
-
)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export function regular() {
|
|
135
|
-
return <TabNav ariaAttr={ariaAttr} items={defaultItems} onClick={action('onClick')} />
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export function withButtonActions() {
|
|
139
|
-
return <TabNav ariaAttr={ariaAttr} items={defaultItems} actions={buttonActions} onClick={action('onClick')} />
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function withTextActions() {
|
|
143
|
-
return <TabNav ariaAttr={ariaAttr} items={defaultItems} actions={textActions} onClick={action('onClick')} />
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function withLinkActions() {
|
|
147
|
-
return <TabNav ariaAttr={ariaAttr} items={defaultItems} actions={linkActions} onClick={action('onClick')} />
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export function withNavigation() {
|
|
151
|
-
return (
|
|
152
|
-
<BrowserRouter>
|
|
153
|
-
<TabNav ariaAttr={ariaAttr} items={navigationItems} onClick={action('onClick')} />
|
|
154
|
-
</BrowserRouter>
|
|
155
|
-
)
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export function withMixedEnabledVisibleItems() {
|
|
159
|
-
return (
|
|
160
|
-
<BrowserRouter>
|
|
161
|
-
<TabNav ariaAttr={ariaAttr} items={mixedEnabledVisibleItems} onClick={action('onClick')} />
|
|
162
|
-
</BrowserRouter>
|
|
163
|
-
)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export function inactive() {
|
|
167
|
-
return <TabNav ariaAttr={ariaAttr} items={defaultItems} onClick={action('onClick')} state={tabNavState.inactive} />
|
|
168
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { defaultItems as items, regular, withButtonActions, withTextActions, withLinkActions, inactive } from './TabNav.int.story'
|
|
2
|
-
|
|
3
|
-
jest.mock('@papillonarts/library/array', () => ({
|
|
4
|
-
getIndexItems: () => {},
|
|
5
|
-
getIndexItemsWithSelected: () => {},
|
|
6
|
-
}))
|
|
7
|
-
|
|
8
|
-
const libraryArrayMockObject = require('@papillonarts/library/array')
|
|
9
|
-
|
|
10
|
-
describe('<TabNav />', () => {
|
|
11
|
-
const indexItemsDataObject = [
|
|
12
|
-
{ ...items[0], index: 0 },
|
|
13
|
-
{ ...items[1], index: 1 },
|
|
14
|
-
]
|
|
15
|
-
|
|
16
|
-
const newIndexItemsWithSelectedDataObject = [
|
|
17
|
-
{ ...items[0], index: 0, isSelected: true, enabled: true, visible: true },
|
|
18
|
-
{ ...items[1], index: 1, isSelected: false, enabled: true, visible: true },
|
|
19
|
-
]
|
|
20
|
-
|
|
21
|
-
function mockLibraryForRegularItems() {
|
|
22
|
-
jest.spyOn(libraryArrayMockObject, 'getIndexItems').mockReturnValue(indexItemsDataObject)
|
|
23
|
-
|
|
24
|
-
jest.spyOn(libraryArrayMockObject, 'getIndexItemsWithSelected').mockReturnValue(newIndexItemsWithSelectedDataObject)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
afterEach(() => jest.clearAllMocks())
|
|
28
|
-
|
|
29
|
-
describe('Render', () => {
|
|
30
|
-
test('must match regular()', () => {
|
|
31
|
-
mockLibraryForRegularItems()
|
|
32
|
-
expect(global.renderToJSON(regular())).toMatchSnapshot()
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
test('must match withButtonActions()', () => {
|
|
36
|
-
mockLibraryForRegularItems()
|
|
37
|
-
expect(global.renderToJSON(withButtonActions())).toMatchSnapshot()
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
test('must match withTextActions()', () => {
|
|
41
|
-
mockLibraryForRegularItems()
|
|
42
|
-
expect(global.renderToJSON(withTextActions())).toMatchSnapshot()
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
test('must match withLinkActions()', () => {
|
|
46
|
-
mockLibraryForRegularItems()
|
|
47
|
-
expect(global.renderToJSON(withLinkActions())).toMatchSnapshot()
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
test('must match inactive()', () => {
|
|
51
|
-
mockLibraryForRegularItems()
|
|
52
|
-
expect(global.renderToJSON(inactive())).toMatchSnapshot()
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
})
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export const underlineNavItemType = {
|
|
2
|
-
a: 'a',
|
|
3
|
-
button: 'button',
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export const underlineNavAlignmentType = {
|
|
7
|
-
right: 'right',
|
|
8
|
-
left: 'left',
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const defaultProps = {
|
|
12
|
-
className: null,
|
|
13
|
-
actions: null,
|
|
14
|
-
align: 'left',
|
|
15
|
-
fullContainer: false,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface AriaAttrType {
|
|
19
|
-
label: string
|
|
20
|
-
selected: string
|
|
21
|
-
current: boolean | false | true | 'page' | 'step' | 'location' | 'date' | 'time'
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface ItemType {
|
|
25
|
-
href: string
|
|
26
|
-
icon: string
|
|
27
|
-
text: string
|
|
28
|
-
html: React.ReactNode
|
|
29
|
-
isSelected: boolean
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface UnderlineNavProps {
|
|
33
|
-
className?: string
|
|
34
|
-
ariaAttr: AriaAttrType
|
|
35
|
-
items: ItemType
|
|
36
|
-
itemType: typeof underlineNavItemType.a | typeof underlineNavItemType.button
|
|
37
|
-
actions?: React.ReactNode[]
|
|
38
|
-
align?: typeof underlineNavAlignmentType.right | typeof underlineNavAlignmentType.left
|
|
39
|
-
fullContainer?: boolean
|
|
40
|
-
onClick: (value) => void
|
|
41
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { Fragment } from 'react'
|
|
2
|
-
import cx from 'classnames'
|
|
3
|
-
import { v1 as uuidv1 } from 'uuid'
|
|
4
|
-
import { getIndexItems, getIndexItemsWithSelected } from '@papillonarts/library/array'
|
|
5
|
-
import { useState } from '@papillonarts/library/hooks'
|
|
6
|
-
import { UnderlineNavProps, defaultProps, underlineNavAlignmentType } from './UnderlineNav.prop'
|
|
7
|
-
import styles from './UnderlineNav.scss'
|
|
8
|
-
import containerStyles from '../../Layout/container.scss'
|
|
9
|
-
import { Icon, iconSize } from '../../Icon'
|
|
10
|
-
|
|
11
|
-
export function UnderlineNav({
|
|
12
|
-
className = defaultProps.className,
|
|
13
|
-
ariaAttr,
|
|
14
|
-
items,
|
|
15
|
-
itemType,
|
|
16
|
-
actions = defaultProps.actions,
|
|
17
|
-
align = defaultProps.align,
|
|
18
|
-
fullContainer = defaultProps.fullContainer,
|
|
19
|
-
onClick,
|
|
20
|
-
}: UnderlineNavProps) {
|
|
21
|
-
const [indexItems, setIndexItems] = useState(getIndexItems(items))
|
|
22
|
-
const { label, selected, current } = ariaAttr
|
|
23
|
-
|
|
24
|
-
function renderActions() {
|
|
25
|
-
return <div className={styles['UnderlineNav-actions']}>{actions}</div>
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function renderBody() {
|
|
29
|
-
return (
|
|
30
|
-
<Fragment>
|
|
31
|
-
{align === underlineNavAlignmentType.right && actions && renderActions()}
|
|
32
|
-
<div className={styles['UnderlineNav-body']} role="tablist">
|
|
33
|
-
{indexItems.map((indexItem) => {
|
|
34
|
-
const { href, icon, text, html, isSelected } = indexItem
|
|
35
|
-
const anchorOtherProps = isSelected ? { ...{ 'aria-selected': selected } } : null
|
|
36
|
-
const buttonOtherProps = isSelected ? { ...{ 'aria-current': current } } : null
|
|
37
|
-
|
|
38
|
-
switch (itemType) {
|
|
39
|
-
case 'button':
|
|
40
|
-
return (
|
|
41
|
-
<button
|
|
42
|
-
key={uuidv1()}
|
|
43
|
-
onClick={(e) => {
|
|
44
|
-
e.preventDefault()
|
|
45
|
-
const newIndexItems = getIndexItemsWithSelected(indexItems, indexItem)
|
|
46
|
-
setIndexItems(newIndexItems)
|
|
47
|
-
onClick(newIndexItems)
|
|
48
|
-
}}
|
|
49
|
-
className={styles['UnderlineNav-item']}
|
|
50
|
-
role="tab"
|
|
51
|
-
type="button"
|
|
52
|
-
// @ts-ignore
|
|
53
|
-
href={href}
|
|
54
|
-
{...anchorOtherProps}
|
|
55
|
-
>
|
|
56
|
-
{icon && <Icon className={styles['UnderlineNav-octicon']} icon={icon} size={iconSize.small} />}
|
|
57
|
-
{html || null}
|
|
58
|
-
{text}
|
|
59
|
-
</button>
|
|
60
|
-
)
|
|
61
|
-
case 'a':
|
|
62
|
-
return (
|
|
63
|
-
<a
|
|
64
|
-
key={uuidv1()}
|
|
65
|
-
onClick={(e) => {
|
|
66
|
-
e.preventDefault()
|
|
67
|
-
const newIndexItems = getIndexItemsWithSelected(indexItems, indexItem)
|
|
68
|
-
setIndexItems(newIndexItems)
|
|
69
|
-
onClick(newIndexItems)
|
|
70
|
-
}}
|
|
71
|
-
className={styles['UnderlineNav-item']}
|
|
72
|
-
href={href}
|
|
73
|
-
{...buttonOtherProps}
|
|
74
|
-
>
|
|
75
|
-
{icon && <Icon className={styles['UnderlineNav-octicon']} icon={icon} size={iconSize.small} />}
|
|
76
|
-
{html || null}
|
|
77
|
-
{text}
|
|
78
|
-
</a>
|
|
79
|
-
)
|
|
80
|
-
default:
|
|
81
|
-
return null
|
|
82
|
-
}
|
|
83
|
-
})}
|
|
84
|
-
</div>
|
|
85
|
-
{align === underlineNavAlignmentType.left && actions && renderActions()}
|
|
86
|
-
</Fragment>
|
|
87
|
-
)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function renderBodyFullContainer() {
|
|
91
|
-
return <div className={cx(containerStyles['container-lg'], styles['UnderlineNav-container'])}>{renderBody()}</div>
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return (
|
|
95
|
-
<nav
|
|
96
|
-
className={cx(className, styles.UnderlineNav, {
|
|
97
|
-
[styles['UnderlineNav--right']]: align === underlineNavAlignmentType.right,
|
|
98
|
-
[styles['UnderlineNav--full']]: fullContainer === true,
|
|
99
|
-
})}
|
|
100
|
-
aria-label={label}
|
|
101
|
-
>
|
|
102
|
-
{fullContainer === false && renderBody()}
|
|
103
|
-
{fullContainer === true && renderBodyFullContainer()}
|
|
104
|
-
</nav>
|
|
105
|
-
)
|
|
106
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { Fragment } from 'react'
|
|
2
|
-
import { v1 as uuidv1 } from 'uuid'
|
|
3
|
-
import { action } from 'storybook/actions'
|
|
4
|
-
import { withTests } from '@storybook/addon-jest'
|
|
5
|
-
import buttonStyles from '../../../Button/Button.scss'
|
|
6
|
-
import counterStyles from '../../../Label/counters.scss'
|
|
7
|
-
import { underlineNavItemType, underlineNavAlignmentType } from '../UnderlineNav.prop'
|
|
8
|
-
import { iconName } from '../../../Icon/Icon.prop'
|
|
9
|
-
import results from '../../../../../../../.jest-test-results.json'
|
|
10
|
-
|
|
11
|
-
const UnderlineNav =
|
|
12
|
-
process.env.NODE_ENV === 'develop' || process.env.NODE_ENV === 'test'
|
|
13
|
-
? require('../../../../index').primer.Navigation.UnderlineNav
|
|
14
|
-
: require('../../../../../build').primer.Navigation.UnderlineNav
|
|
15
|
-
|
|
16
|
-
export default {
|
|
17
|
-
title: 'Primer/Molecule/Navigation/UnderlineNav',
|
|
18
|
-
component: UnderlineNav,
|
|
19
|
-
decorators: [withTests({ results })],
|
|
20
|
-
parameters: { jest: ['UnderlineNav.int.test.js'] },
|
|
21
|
-
excludeStories: ['ariaAttr', 'buttonItems', 'anchorItems', 'iconItems', 'fullContainerItems', 'custom'],
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const ariaAttr = {
|
|
25
|
-
label: 'Foo bar',
|
|
26
|
-
selected: 'true',
|
|
27
|
-
current: 'page',
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const buttonItems = [
|
|
31
|
-
{ text: 'Item 1', isSelected: true },
|
|
32
|
-
{ text: 'Item 2', isSelected: false },
|
|
33
|
-
{ text: 'Item 3', isSelected: false },
|
|
34
|
-
{ text: 'Item 4', isSelected: false },
|
|
35
|
-
]
|
|
36
|
-
|
|
37
|
-
export const anchorItems = [
|
|
38
|
-
{ href: '#url', text: 'Item 1', isSelected: true },
|
|
39
|
-
{ href: '#url', text: 'Item 2', isSelected: false },
|
|
40
|
-
{ href: '#url', text: 'Item 3', isSelected: false },
|
|
41
|
-
{ href: '#url', text: 'Item 4', isSelected: false },
|
|
42
|
-
]
|
|
43
|
-
|
|
44
|
-
export const iconItems = [
|
|
45
|
-
{ href: '#url', icon: iconName.Tools16, html: <span>Item 1</span>, isSelected: true },
|
|
46
|
-
{
|
|
47
|
-
href: '#url',
|
|
48
|
-
icon: iconName.Tools16,
|
|
49
|
-
html: (
|
|
50
|
-
<Fragment>
|
|
51
|
-
<span>Item 2</span>
|
|
52
|
-
<span className={counterStyles.Counter}>10</span>
|
|
53
|
-
</Fragment>
|
|
54
|
-
),
|
|
55
|
-
isSelected: false,
|
|
56
|
-
},
|
|
57
|
-
{ href: '#url', icon: iconName.Tools16, html: <span>Item 3</span>, isSelected: false },
|
|
58
|
-
{ href: '#url', icon: iconName.Tools16, html: <span>Item 4</span>, isSelected: false },
|
|
59
|
-
]
|
|
60
|
-
|
|
61
|
-
export const fullContainerItems = [
|
|
62
|
-
{ href: '#url', icon: iconName.Tools16, html: <span>Item 1</span>, isSelected: true },
|
|
63
|
-
{
|
|
64
|
-
href: '#url',
|
|
65
|
-
icon: iconName.Tools16,
|
|
66
|
-
html: (
|
|
67
|
-
<Fragment>
|
|
68
|
-
<span>Item 2</span>
|
|
69
|
-
<span className={counterStyles.Counter}>10</span>
|
|
70
|
-
</Fragment>
|
|
71
|
-
),
|
|
72
|
-
isSelected: false,
|
|
73
|
-
},
|
|
74
|
-
{ href: '#url', icon: iconName.Tools16, html: <span>Item 3</span>, isSelected: false },
|
|
75
|
-
{ href: '#url', icon: iconName.Tools16, html: <span>Item 4</span>, isSelected: false },
|
|
76
|
-
]
|
|
77
|
-
|
|
78
|
-
const actionButton = (
|
|
79
|
-
<a key={uuidv1()} href="#url" className={buttonStyles.btn}>
|
|
80
|
-
Button
|
|
81
|
-
</a>
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
const actions = [actionButton]
|
|
85
|
-
|
|
86
|
-
export function custom(items, itemType, onClick) {
|
|
87
|
-
return <UnderlineNav ariaAttr={ariaAttr} items={items} itemType={itemType} onClick={onClick} />
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function regular() {
|
|
91
|
-
return <UnderlineNav ariaAttr={ariaAttr} items={buttonItems} itemType={underlineNavItemType.button} onClick={action('onClick')} />
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function withActions() {
|
|
95
|
-
return (
|
|
96
|
-
<UnderlineNav ariaAttr={ariaAttr} items={anchorItems} itemType={underlineNavItemType.a} actions={actions} onClick={action('onClick')} />
|
|
97
|
-
)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function rightAligned() {
|
|
101
|
-
return (
|
|
102
|
-
<UnderlineNav
|
|
103
|
-
ariaAttr={ariaAttr}
|
|
104
|
-
items={anchorItems}
|
|
105
|
-
itemType={underlineNavItemType.a}
|
|
106
|
-
align={underlineNavAlignmentType.right}
|
|
107
|
-
onClick={action('onClick')}
|
|
108
|
-
/>
|
|
109
|
-
)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function rightAlignedWithActions() {
|
|
113
|
-
return (
|
|
114
|
-
<UnderlineNav
|
|
115
|
-
ariaAttr={ariaAttr}
|
|
116
|
-
items={anchorItems}
|
|
117
|
-
itemType={underlineNavItemType.a}
|
|
118
|
-
align={underlineNavAlignmentType.right}
|
|
119
|
-
actions={actions}
|
|
120
|
-
onClick={action('onClick')}
|
|
121
|
-
/>
|
|
122
|
-
)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function withIcons() {
|
|
126
|
-
return <UnderlineNav ariaAttr={ariaAttr} items={iconItems} itemType={underlineNavItemType.a} onClick={action('onClick')} />
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export function fullContainer() {
|
|
130
|
-
return (
|
|
131
|
-
<UnderlineNav
|
|
132
|
-
ariaAttr={ariaAttr}
|
|
133
|
-
items={fullContainerItems}
|
|
134
|
-
itemType={underlineNavItemType.a}
|
|
135
|
-
actions={actions}
|
|
136
|
-
fullContainer
|
|
137
|
-
onClick={action('onClick')}
|
|
138
|
-
/>
|
|
139
|
-
)
|
|
140
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
buttonItems,
|
|
3
|
-
regular,
|
|
4
|
-
withActions,
|
|
5
|
-
rightAligned,
|
|
6
|
-
rightAlignedWithActions,
|
|
7
|
-
withIcons,
|
|
8
|
-
fullContainer,
|
|
9
|
-
} from './UnderlineNav.int.story'
|
|
10
|
-
|
|
11
|
-
jest.mock('@papillonarts/library/array', () => ({
|
|
12
|
-
getIndexItems: () => {},
|
|
13
|
-
getIndexItemsWithSelected: () => {},
|
|
14
|
-
}))
|
|
15
|
-
|
|
16
|
-
jest.mock('@papillonarts/library/hooks', () => ({
|
|
17
|
-
useState: () => {},
|
|
18
|
-
}))
|
|
19
|
-
|
|
20
|
-
const libraryArrayMockObject = require('@papillonarts/library/array')
|
|
21
|
-
const libraryHooksMockObject = require('@papillonarts/library/hooks')
|
|
22
|
-
|
|
23
|
-
describe('<UnderlineNav />', () => {
|
|
24
|
-
let indexButtonItemsDataObject = [
|
|
25
|
-
{ ...buttonItems[0], index: 0 },
|
|
26
|
-
{ ...buttonItems[1], index: 1 },
|
|
27
|
-
{ ...buttonItems[2], index: 2 },
|
|
28
|
-
{ ...buttonItems[3], index: 3 },
|
|
29
|
-
]
|
|
30
|
-
|
|
31
|
-
const newIndexButtonItemsWithSelectedDataObject = [
|
|
32
|
-
{ ...buttonItems[0], index: 0, isSelected: true },
|
|
33
|
-
{ ...buttonItems[1], index: 1, isSelected: false },
|
|
34
|
-
{ ...buttonItems[2], index: 2, isSelected: false },
|
|
35
|
-
{ ...buttonItems[3], index: 3, isSelected: false },
|
|
36
|
-
]
|
|
37
|
-
|
|
38
|
-
const setIndexButtonItemsMockFn = jest.fn((indexButtonItems) => {
|
|
39
|
-
indexButtonItemsDataObject = indexButtonItems
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
function mockLibraryForButtonItems() {
|
|
43
|
-
jest.spyOn(libraryArrayMockObject, 'getIndexItems').mockReturnValue(indexButtonItemsDataObject)
|
|
44
|
-
|
|
45
|
-
jest.spyOn(libraryArrayMockObject, 'getIndexItemsWithSelected').mockReturnValue(newIndexButtonItemsWithSelectedDataObject)
|
|
46
|
-
|
|
47
|
-
jest.spyOn(libraryHooksMockObject, 'useState').mockImplementation(() => [indexButtonItemsDataObject, setIndexButtonItemsMockFn])
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
describe('Render', () => {
|
|
51
|
-
test('must match regular()', () => {
|
|
52
|
-
mockLibraryForButtonItems()
|
|
53
|
-
expect(global.renderToJSON(regular())).toMatchSnapshot()
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
test('must match withActions()', () => {
|
|
57
|
-
mockLibraryForButtonItems()
|
|
58
|
-
expect(global.renderToJSON(withActions())).toMatchSnapshot()
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
test('must match rightAligned()', () => {
|
|
62
|
-
mockLibraryForButtonItems()
|
|
63
|
-
expect(global.renderToJSON(rightAligned())).toMatchSnapshot()
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
test('must match rightAlignedWithActions()', () => {
|
|
67
|
-
mockLibraryForButtonItems()
|
|
68
|
-
expect(global.renderToJSON(rightAlignedWithActions())).toMatchSnapshot()
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
test('must match withIcons()', () => {
|
|
72
|
-
mockLibraryForButtonItems()
|
|
73
|
-
expect(global.renderToJSON(withIcons())).toMatchSnapshot()
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
test('must match fullContainer()', () => {
|
|
77
|
-
mockLibraryForButtonItems()
|
|
78
|
-
expect(global.renderToJSON(fullContainer())).toMatchSnapshot()
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
})
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Menu } from './Menu'
|
|
2
|
-
import { TabNav, tabNavState } from './TabNav'
|
|
3
|
-
import { UnderlineNav, underlineNavItemType, underlineNavAlignmentType } from './UnderlineNav'
|
|
4
|
-
|
|
5
|
-
export const Navigation = {
|
|
6
|
-
Menu,
|
|
7
|
-
TabNav,
|
|
8
|
-
tabNavState,
|
|
9
|
-
UnderlineNav,
|
|
10
|
-
underlineNavItemType,
|
|
11
|
-
underlineNavAlignmentType,
|
|
12
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
export const previousNextState = {
|
|
2
|
-
active: 'active',
|
|
3
|
-
inactive: 'inactive',
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export const defaultProps = {
|
|
7
|
-
className: null,
|
|
8
|
-
previous: {
|
|
9
|
-
rel: 'previous',
|
|
10
|
-
href: '#url',
|
|
11
|
-
ariaAttr: {
|
|
12
|
-
label: 'Previous',
|
|
13
|
-
},
|
|
14
|
-
text: '<',
|
|
15
|
-
},
|
|
16
|
-
next: {
|
|
17
|
-
rel: 'next',
|
|
18
|
-
href: '#url',
|
|
19
|
-
ariaAttr: {
|
|
20
|
-
label: 'Next',
|
|
21
|
-
},
|
|
22
|
-
text: '>',
|
|
23
|
-
},
|
|
24
|
-
state: previousNextState.active,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface AriaAttrType {
|
|
28
|
-
label: string
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface PreviousNextType {
|
|
32
|
-
rel: string
|
|
33
|
-
href: string
|
|
34
|
-
ariaAttr: AriaAttrType
|
|
35
|
-
text: string
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface currentPageType {
|
|
39
|
-
indexItems: React.ReactNode[]
|
|
40
|
-
currentIndex: number
|
|
41
|
-
canMoveBackwards: boolean
|
|
42
|
-
canMoveForward: boolean
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export interface PreviousNextProps {
|
|
46
|
-
className?: string
|
|
47
|
-
ariaAttr: AriaAttrType
|
|
48
|
-
currentPage: currentPageType
|
|
49
|
-
previous?: PreviousNextType
|
|
50
|
-
next?: PreviousNextType
|
|
51
|
-
onClick: (value) => void
|
|
52
|
-
state?: typeof previousNextState.active | typeof previousNextState.inactive
|
|
53
|
-
}
|