@papillonarts/components 0.10.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,33 +0,0 @@
|
|
|
1
|
-
export const dropdownState = {
|
|
2
|
-
active: 'active',
|
|
3
|
-
inactive: 'inactive',
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export const defaultProps = {
|
|
7
|
-
className: null,
|
|
8
|
-
ariaAttr: {
|
|
9
|
-
haspopup: false,
|
|
10
|
-
current: 'page',
|
|
11
|
-
},
|
|
12
|
-
state: dropdownState.active,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface AriaAttrType {
|
|
16
|
-
haspopup: boolean
|
|
17
|
-
current: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface ItemType {
|
|
21
|
-
href: string
|
|
22
|
-
text: string
|
|
23
|
-
isSelected: boolean
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface DropdownProps {
|
|
27
|
-
className?: string
|
|
28
|
-
summary: string
|
|
29
|
-
ariaAttr?: AriaAttrType
|
|
30
|
-
items: ItemType[]
|
|
31
|
-
onClick: (value) => void
|
|
32
|
-
state?: typeof dropdownState.active | typeof dropdownState.inactive
|
|
33
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import cx from 'classnames'
|
|
2
|
-
import { v1 as uuidv1 } from 'uuid'
|
|
3
|
-
import detailsUtilityStyles from '@papillonarts/css/build/primer/utilities/details.scss'
|
|
4
|
-
import displayStyles from '@papillonarts/css/build/primer/utilities/visibility-display.scss'
|
|
5
|
-
import layoutStyles from '@papillonarts/css/build/primer/utilities/layout.scss'
|
|
6
|
-
import flexboxStyles from '@papillonarts/css/build/primer/utilities/flexbox.scss'
|
|
7
|
-
import { getIndexItems, getIndexItemsWithSelected } from '@papillonarts/library/array'
|
|
8
|
-
import { useRef } from '@papillonarts/library/hooks'
|
|
9
|
-
import buttonStyles from '../Button/Button.scss'
|
|
10
|
-
import { DropdownProps, defaultProps, dropdownState } from './Dropdown.prop'
|
|
11
|
-
import styles from './Dropdown.scss'
|
|
12
|
-
|
|
13
|
-
export function Dropdown({
|
|
14
|
-
className = defaultProps.className,
|
|
15
|
-
summary,
|
|
16
|
-
ariaAttr = defaultProps.ariaAttr,
|
|
17
|
-
items,
|
|
18
|
-
onClick,
|
|
19
|
-
state = defaultProps.state,
|
|
20
|
-
}: DropdownProps) {
|
|
21
|
-
const details = useRef(null)
|
|
22
|
-
|
|
23
|
-
if (!items) {
|
|
24
|
-
return null
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const indexItems = getIndexItems(items)
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<div className={className}>
|
|
31
|
-
<details
|
|
32
|
-
ref={details}
|
|
33
|
-
className={cx(
|
|
34
|
-
styles.dropdown,
|
|
35
|
-
detailsUtilityStyles['details-reset'],
|
|
36
|
-
detailsUtilityStyles['details-overlay'],
|
|
37
|
-
displayStyles['d-inline-block'],
|
|
38
|
-
{
|
|
39
|
-
[styles['dropdown-inactive']]: state === dropdownState.inactive,
|
|
40
|
-
},
|
|
41
|
-
)}
|
|
42
|
-
>
|
|
43
|
-
<summary className={cx(buttonStyles.btn)} aria-haspopup={ariaAttr?.haspopup ?? false}>
|
|
44
|
-
<div
|
|
45
|
-
className={cx(displayStyles['d-flex'], flexboxStyles['flex-justify-between'], flexboxStyles['flex-items-center'], {
|
|
46
|
-
[styles['dropdown-inactive']]: state === dropdownState.inactive,
|
|
47
|
-
})}
|
|
48
|
-
>
|
|
49
|
-
<div>{summary}</div> <div className={styles['dropdown-caret']} />
|
|
50
|
-
</div>
|
|
51
|
-
</summary>
|
|
52
|
-
|
|
53
|
-
<ul className={cx(styles['dropdown-menu'], styles['dropdown-menu-se'], layoutStyles['width-full'])}>
|
|
54
|
-
{indexItems.map((indexItem) => {
|
|
55
|
-
const { href, text /* isSelected */ } = indexItem
|
|
56
|
-
|
|
57
|
-
// const itemOtherProps = isSelected ? { ...{ 'aria-current': ariaAttr?.current } } : null
|
|
58
|
-
|
|
59
|
-
return (
|
|
60
|
-
<li key={uuidv1()}>
|
|
61
|
-
<a
|
|
62
|
-
onClick={(e) => {
|
|
63
|
-
e.preventDefault()
|
|
64
|
-
const newIndexItems = getIndexItemsWithSelected(indexItems, indexItem)
|
|
65
|
-
onClick({
|
|
66
|
-
summary: text,
|
|
67
|
-
ariaAttr,
|
|
68
|
-
items: newIndexItems.map((newIndexItem) =>
|
|
69
|
-
(({
|
|
70
|
-
id: newIndexItemId,
|
|
71
|
-
href: newIndexItemHref,
|
|
72
|
-
text: newIndexItemText,
|
|
73
|
-
'date-modified': dateModified,
|
|
74
|
-
'date-created': dateCreated,
|
|
75
|
-
isSelected: newIndexItemIsSelected,
|
|
76
|
-
}) => ({
|
|
77
|
-
id: newIndexItemId,
|
|
78
|
-
href: newIndexItemHref,
|
|
79
|
-
text: newIndexItemText,
|
|
80
|
-
'date-modified': dateModified,
|
|
81
|
-
'date-created': dateCreated,
|
|
82
|
-
isSelected: newIndexItemIsSelected,
|
|
83
|
-
}))(newIndexItem),
|
|
84
|
-
),
|
|
85
|
-
})
|
|
86
|
-
details.current.removeAttribute('open')
|
|
87
|
-
}}
|
|
88
|
-
className={styles['dropdown-item']}
|
|
89
|
-
href={href}
|
|
90
|
-
// @ts-ignore
|
|
91
|
-
// {...itemOtherProps}
|
|
92
|
-
>
|
|
93
|
-
{text}
|
|
94
|
-
</a>
|
|
95
|
-
</li>
|
|
96
|
-
)
|
|
97
|
-
})}
|
|
98
|
-
</ul>
|
|
99
|
-
</details>
|
|
100
|
-
</div>
|
|
101
|
-
)
|
|
102
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { action } from 'storybook/actions'
|
|
2
|
-
import { withTests } from '@storybook/addon-jest'
|
|
3
|
-
import { dropdownState } from '../Dropdown.prop'
|
|
4
|
-
import results from '../../../../../../.jest-test-results.json'
|
|
5
|
-
|
|
6
|
-
const Dropdown =
|
|
7
|
-
process.env.NODE_ENV === 'develop' || process.env.NODE_ENV === 'test'
|
|
8
|
-
? require('../../../index').primer.Dropdown.Dropdown
|
|
9
|
-
: require('../../../../build').primer.Dropdown.Dropdown
|
|
10
|
-
|
|
11
|
-
export default {
|
|
12
|
-
title: 'Primer/Atom/Dropdown',
|
|
13
|
-
component: Dropdown,
|
|
14
|
-
decorators: [withTests({ results })],
|
|
15
|
-
parameters: { jest: ['Dropdown.int.test.js'] },
|
|
16
|
-
excludeStories: ['summary', 'ariaAttr', 'items', 'custom'],
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const summary = 'Dropdown'
|
|
20
|
-
|
|
21
|
-
export const ariaAttr = {
|
|
22
|
-
haspopup: true,
|
|
23
|
-
current: 'page',
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const items = [
|
|
27
|
-
{ href: '#url', text: 'Dropdown Item 1', isSelected: true },
|
|
28
|
-
{ href: '#url', text: 'Dropdown Item 2', isSelected: false },
|
|
29
|
-
{ href: '#url', text: 'Dropdown Item 3', isSelected: false },
|
|
30
|
-
{ href: '#url', text: 'Dropdown Item 4', isSelected: false },
|
|
31
|
-
]
|
|
32
|
-
|
|
33
|
-
export function custom(onClick) {
|
|
34
|
-
return <Dropdown summary={summary} ariaAttr={ariaAttr} items={items} onClick={onClick} />
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function regular() {
|
|
38
|
-
return <Dropdown summary={summary} ariaAttr={ariaAttr} items={items} onClick={action('onClick')} />
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function inactive() {
|
|
42
|
-
return <Dropdown summary={summary} ariaAttr={ariaAttr} items={items} onClick={action('onClick')} state={dropdownState.inactive} />
|
|
43
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { items, regular, inactive } from './Dropdown.int.story'
|
|
2
|
-
|
|
3
|
-
jest.mock('@papillonarts/library/array', () => ({
|
|
4
|
-
getIndexItems: () => {},
|
|
5
|
-
getIndexItemsWithSelected: () => {},
|
|
6
|
-
}))
|
|
7
|
-
|
|
8
|
-
jest.mock('@papillonarts/library/hooks', () => ({
|
|
9
|
-
useRef: () => {},
|
|
10
|
-
}))
|
|
11
|
-
|
|
12
|
-
const libraryArrayMockObject = require('@papillonarts/library/array')
|
|
13
|
-
const libraryHooksMockObject = require('@papillonarts/library/hooks')
|
|
14
|
-
|
|
15
|
-
describe('<Dropdown />', () => {
|
|
16
|
-
const indexItemsDataObject = [
|
|
17
|
-
{ ...items[0], index: 0 },
|
|
18
|
-
{ ...items[1], index: 1 },
|
|
19
|
-
{ ...items[2], index: 2 },
|
|
20
|
-
{ ...items[3], index: 3 },
|
|
21
|
-
]
|
|
22
|
-
|
|
23
|
-
const newIndexItemsWithSelectedDataObject = [
|
|
24
|
-
{ ...items[0], index: 0, isSelected: true },
|
|
25
|
-
{ ...items[1], index: 1, isSelected: false },
|
|
26
|
-
{ ...items[2], index: 2, isSelected: false },
|
|
27
|
-
{ ...items[3], index: 3, isSelected: false },
|
|
28
|
-
]
|
|
29
|
-
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
jest.spyOn(libraryArrayMockObject, 'getIndexItems').mockReturnValue(indexItemsDataObject)
|
|
32
|
-
|
|
33
|
-
jest.spyOn(libraryArrayMockObject, 'getIndexItemsWithSelected').mockReturnValue(newIndexItemsWithSelectedDataObject)
|
|
34
|
-
|
|
35
|
-
jest.spyOn(libraryHooksMockObject, 'useRef').mockImplementation(() => ({
|
|
36
|
-
current: {
|
|
37
|
-
removeAttribute: () => {},
|
|
38
|
-
},
|
|
39
|
-
}))
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
afterEach(() => jest.clearAllMocks())
|
|
43
|
-
|
|
44
|
-
describe('Render', () => {
|
|
45
|
-
test('must match regular()', () => {
|
|
46
|
-
expect(global.renderToJSON(regular())).toMatchSnapshot()
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
test('must match inacive()', () => {
|
|
50
|
-
expect(global.renderToJSON(inactive())).toMatchSnapshot()
|
|
51
|
-
})
|
|
52
|
-
})
|
|
53
|
-
})
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-unused-vars, no-console */
|
|
2
|
-
import { Component } from 'react'
|
|
3
|
-
import { ErrorBoundaryProps } from './ErrorBoundary.prop'
|
|
4
|
-
|
|
5
|
-
export class ErrorBoundary extends Component<ErrorBoundaryProps> {
|
|
6
|
-
constructor(props) {
|
|
7
|
-
super(props)
|
|
8
|
-
this.state = { hasError: false }
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
static getDerivedStateFromError(error) {
|
|
12
|
-
// Update state so the next render will show the fallback UI.
|
|
13
|
-
return { hasError: true }
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
componentDidCatch(error, errorInfo) {
|
|
17
|
-
// You can also log the error to an error reporting service
|
|
18
|
-
console.log('~error~', error)
|
|
19
|
-
console.log('~errorInfo~', errorInfo)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
render() {
|
|
23
|
-
// @ts-ignore
|
|
24
|
-
const { hasError } = this.state
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
const { children } = this.props
|
|
27
|
-
|
|
28
|
-
if (hasError) {
|
|
29
|
-
// You can render any custom fallback UI
|
|
30
|
-
return <h1>Something went wrong.</h1>
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return children
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { withTests } from '@storybook/addon-jest'
|
|
2
|
-
import results from '../../../../../../.jest-test-results.json'
|
|
3
|
-
|
|
4
|
-
const ErrorBoundary =
|
|
5
|
-
process.env.NODE_ENV === 'develop' || process.env.NODE_ENV === 'test'
|
|
6
|
-
? require('../../../index').primer.ErrorBoundary
|
|
7
|
-
: require('../../../../build').primer.ErrorBoundary
|
|
8
|
-
|
|
9
|
-
export default {
|
|
10
|
-
title: 'Primer/Molecule/ErrorBoundary',
|
|
11
|
-
component: ErrorBoundary,
|
|
12
|
-
decorators: [withTests({ results })],
|
|
13
|
-
parameters: { jest: ['ErrorBoundary.int.test.js'] },
|
|
14
|
-
excludeStories: ['custom'],
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function regular() {
|
|
18
|
-
return (
|
|
19
|
-
<ErrorBoundary>
|
|
20
|
-
<div />
|
|
21
|
-
</ErrorBoundary>
|
|
22
|
-
)
|
|
23
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { ErrorBoundary } from './ErrorBoundary'
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export const checkboxState = {
|
|
2
|
-
active: 'active',
|
|
3
|
-
inactive: 'inactive',
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export const inputType = {
|
|
7
|
-
checkbox: 'checkbox',
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const defaultProps = {
|
|
11
|
-
dataTest: null,
|
|
12
|
-
className: null,
|
|
13
|
-
htmlFor: 'checkbox',
|
|
14
|
-
inputType: inputType.checkbox,
|
|
15
|
-
isChecked: false,
|
|
16
|
-
text: null,
|
|
17
|
-
state: checkboxState.active,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface AriaAttrType {
|
|
21
|
-
describedBy: string
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface CheckboxProps {
|
|
25
|
-
dataTest?: string
|
|
26
|
-
className?: string
|
|
27
|
-
htmlFor?: string
|
|
28
|
-
ariaAttr: AriaAttrType
|
|
29
|
-
inputType?: typeof inputType.checkbox
|
|
30
|
-
isChecked?: boolean
|
|
31
|
-
text?: string
|
|
32
|
-
onChange: (value) => void
|
|
33
|
-
state?: typeof checkboxState.active | typeof checkboxState.inactive
|
|
34
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import cx from 'classnames'
|
|
2
|
-
import marginStyles from '@papillonarts/css/build/primer/utilities/margin.scss'
|
|
3
|
-
import { CheckboxProps, defaultProps, checkboxState } from './Checkbox.prop'
|
|
4
|
-
import styles from './Checkbox.scss'
|
|
5
|
-
import formStyles from '../index.scss'
|
|
6
|
-
|
|
7
|
-
export function Checkbox({
|
|
8
|
-
dataTest = defaultProps.dataTest,
|
|
9
|
-
className = defaultProps.className,
|
|
10
|
-
htmlFor = defaultProps.htmlFor,
|
|
11
|
-
ariaAttr,
|
|
12
|
-
inputType = defaultProps.inputType,
|
|
13
|
-
isChecked = defaultProps.isChecked,
|
|
14
|
-
text = defaultProps.text,
|
|
15
|
-
onChange,
|
|
16
|
-
state = defaultProps.state,
|
|
17
|
-
}: CheckboxProps) {
|
|
18
|
-
const { describedBy } = ariaAttr
|
|
19
|
-
|
|
20
|
-
return (
|
|
21
|
-
<div
|
|
22
|
-
data-test={dataTest}
|
|
23
|
-
className={cx(className, marginStyles['m-0'], formStyles['form-checkbox'], {
|
|
24
|
-
[styles['checkbox-inactive']]: state === checkboxState.inactive,
|
|
25
|
-
})}
|
|
26
|
-
>
|
|
27
|
-
<label htmlFor={htmlFor}>
|
|
28
|
-
<input
|
|
29
|
-
type={inputType}
|
|
30
|
-
aria-describedby={describedBy}
|
|
31
|
-
onChange={(event) => {
|
|
32
|
-
onChange(event)
|
|
33
|
-
}}
|
|
34
|
-
checked={isChecked}
|
|
35
|
-
/>
|
|
36
|
-
{text}
|
|
37
|
-
</label>
|
|
38
|
-
</div>
|
|
39
|
-
)
|
|
40
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { action } from 'storybook/actions'
|
|
2
|
-
import { withTests } from '@storybook/addon-jest'
|
|
3
|
-
import { checkboxState } from '../Checkbox.prop'
|
|
4
|
-
import results from '../../../../../../../.jest-test-results.json'
|
|
5
|
-
|
|
6
|
-
const Checkbox =
|
|
7
|
-
process.env.NODE_ENV === 'develop' || process.env.NODE_ENV === 'test'
|
|
8
|
-
? require('../../../../index').primer.Form.Checkbox.Checkbox
|
|
9
|
-
: require('../../../../../build').primer.Form.Checkbox.Checkbox
|
|
10
|
-
|
|
11
|
-
export default {
|
|
12
|
-
title: 'Primer/Atom/Form/Checkbox',
|
|
13
|
-
component: Checkbox,
|
|
14
|
-
decorators: [withTests({ results })],
|
|
15
|
-
parameters: { jest: ['Checkbox.int.test.js'] },
|
|
16
|
-
excludeStories: ['ariaAttr', 'text', 'custom'],
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const ariaAttr = {
|
|
20
|
-
describedBy: 'help-text-for-checkbox',
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const text = {
|
|
24
|
-
isChecked: 'is checked',
|
|
25
|
-
isNotChecked: 'is not checked',
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function custom(onChange) {
|
|
29
|
-
return <Checkbox ariaAttr={ariaAttr} isChecked={true} onChange={onChange} text="is checked" />
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function isChecked() {
|
|
33
|
-
return <Checkbox ariaAttr={ariaAttr} isChecked={true} onChange={action('onChange')} text={text.isChecked} />
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function isCheckedInactive() {
|
|
37
|
-
return (
|
|
38
|
-
<Checkbox ariaAttr={ariaAttr} isChecked={true} onChange={action('onChange')} text={text.isChecked} state={checkboxState.inactive} />
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function isNotChecked() {
|
|
43
|
-
return <Checkbox ariaAttr={ariaAttr} isChecked={false} onChange={action('onChange')} text={text.isNotChecked} />
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function isNotCheckedInactive() {
|
|
47
|
-
return (
|
|
48
|
-
<Checkbox ariaAttr={ariaAttr} isChecked={false} onChange={action('onChange')} text={text.isNotChecked} state={checkboxState.inactive} />
|
|
49
|
-
)
|
|
50
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { isChecked, isNotChecked, isCheckedInactive, isNotCheckedInactive } from './Checkbox.int.story'
|
|
2
|
-
|
|
3
|
-
describe('<Checkbox />', () => {
|
|
4
|
-
afterEach(() => jest.clearAllMocks())
|
|
5
|
-
|
|
6
|
-
describe('Render', () => {
|
|
7
|
-
test('must match isChecked()', () => {
|
|
8
|
-
expect(global.renderToJSON(isChecked())).toMatchSnapshot()
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
test('must match isCheckedInactive()', () => {
|
|
12
|
-
expect(global.renderToJSON(isCheckedInactive())).toMatchSnapshot()
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
test('must match isNotChecked()', () => {
|
|
16
|
-
expect(global.renderToJSON(isNotChecked())).toMatchSnapshot()
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
test('must match isNotCheckedInactive()', () => {
|
|
20
|
-
expect(global.renderToJSON(isNotCheckedInactive())).toMatchSnapshot()
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
})
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export const inputState = {
|
|
2
|
-
active: 'active',
|
|
3
|
-
inactive: 'inactive',
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export const inputType = {
|
|
7
|
-
text: 'text',
|
|
8
|
-
password: 'password',
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const defaultProps = {
|
|
12
|
-
dataTest: null,
|
|
13
|
-
id: null,
|
|
14
|
-
className: null,
|
|
15
|
-
placeholder: null,
|
|
16
|
-
ariaAttr: {
|
|
17
|
-
label: '',
|
|
18
|
-
},
|
|
19
|
-
inputType: inputType.text,
|
|
20
|
-
onFocus: () => {},
|
|
21
|
-
onBlur: () => {},
|
|
22
|
-
state: inputState.active,
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface AriaAttrType {
|
|
26
|
-
label: string
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface InputProps {
|
|
30
|
-
dataTest?: string
|
|
31
|
-
id?: string
|
|
32
|
-
className?: string
|
|
33
|
-
placeholder?: string
|
|
34
|
-
ariaAttr?: AriaAttrType
|
|
35
|
-
inputType?: typeof inputType.text | typeof inputType.password
|
|
36
|
-
value: string
|
|
37
|
-
onChange: (value) => void
|
|
38
|
-
onKeyUp: (value) => void
|
|
39
|
-
onFocus?: (value) => void
|
|
40
|
-
onBlur?: (value) => void
|
|
41
|
-
autoFocus: boolean
|
|
42
|
-
state?: typeof inputState.active | typeof inputState.inactive
|
|
43
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import cx from 'classnames'
|
|
2
|
-
import { InputProps, defaultProps, inputState } from './Input.prop'
|
|
3
|
-
import styles from './Input.scss'
|
|
4
|
-
import formStyles from '../index.scss'
|
|
5
|
-
|
|
6
|
-
export function Input({
|
|
7
|
-
dataTest = defaultProps.dataTest,
|
|
8
|
-
id = defaultProps.id,
|
|
9
|
-
className = defaultProps.className,
|
|
10
|
-
placeholder = defaultProps.placeholder,
|
|
11
|
-
ariaAttr = defaultProps.ariaAttr,
|
|
12
|
-
inputType = defaultProps.inputType,
|
|
13
|
-
value,
|
|
14
|
-
onChange,
|
|
15
|
-
onKeyUp,
|
|
16
|
-
onFocus = defaultProps.onFocus,
|
|
17
|
-
onBlur = defaultProps.onBlur,
|
|
18
|
-
autoFocus,
|
|
19
|
-
state = defaultProps.state,
|
|
20
|
-
}: InputProps) {
|
|
21
|
-
return (
|
|
22
|
-
<input
|
|
23
|
-
data-test={dataTest}
|
|
24
|
-
id={id}
|
|
25
|
-
className={cx(className, formStyles['form-control'], {
|
|
26
|
-
[styles['input-inactive']]: state === inputState.inactive,
|
|
27
|
-
})}
|
|
28
|
-
value={value}
|
|
29
|
-
onChange={(event) => {
|
|
30
|
-
onChange(event)
|
|
31
|
-
}}
|
|
32
|
-
onKeyUp={(event) => {
|
|
33
|
-
onKeyUp(event)
|
|
34
|
-
}}
|
|
35
|
-
onFocus={onFocus}
|
|
36
|
-
onBlur={onBlur}
|
|
37
|
-
type={inputType}
|
|
38
|
-
placeholder={placeholder}
|
|
39
|
-
aria-label={ariaAttr.label}
|
|
40
|
-
autoFocus={autoFocus} // eslint-disable-line
|
|
41
|
-
/>
|
|
42
|
-
)
|
|
43
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { action } from 'storybook/actions'
|
|
2
|
-
import { withTests } from '@storybook/addon-jest'
|
|
3
|
-
import { inputState } from '../Input.prop'
|
|
4
|
-
import results from '../../../../../../../.jest-test-results.json'
|
|
5
|
-
|
|
6
|
-
const Input =
|
|
7
|
-
process.env.NODE_ENV === 'develop' || process.env.NODE_ENV === 'test'
|
|
8
|
-
? require('../../../../index').primer.Form.Input.Input
|
|
9
|
-
: require('../../../../../build').primer.Form.Input.Input
|
|
10
|
-
|
|
11
|
-
export default {
|
|
12
|
-
title: 'Primer/Atom/Form/Input',
|
|
13
|
-
component: Input,
|
|
14
|
-
decorators: [withTests({ results })],
|
|
15
|
-
parameters: { jest: ['Input.int.test.js'] },
|
|
16
|
-
excludeStories: ['placeholder', 'ariaAttr', 'custom'],
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const placeholder = 'Fantastic placeholder'
|
|
20
|
-
|
|
21
|
-
const ariaAttr = {
|
|
22
|
-
label: 'Repository description',
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function custom(onChange, onKeyUp, onFocus, onBlur) {
|
|
26
|
-
return <Input placeholder={placeholder} ariaAttr={ariaAttr} onChange={onChange} onKeyUp={onKeyUp} onFocus={onFocus} onBlur={onBlur} />
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function regular() {
|
|
30
|
-
return (
|
|
31
|
-
<Input
|
|
32
|
-
placeholder={placeholder}
|
|
33
|
-
ariaAttr={ariaAttr}
|
|
34
|
-
onChange={action('onChange')}
|
|
35
|
-
onKeyUp={action('onKeyUp')}
|
|
36
|
-
onFocus={action('onFocus')}
|
|
37
|
-
onBlur={action('onBlur')}
|
|
38
|
-
/>
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function inactive() {
|
|
43
|
-
return (
|
|
44
|
-
<Input
|
|
45
|
-
placeholder={placeholder}
|
|
46
|
-
ariaAttr={ariaAttr}
|
|
47
|
-
onChange={action('onChange')}
|
|
48
|
-
onKeyUp={action('onKeyUp')}
|
|
49
|
-
onFocus={action('onFocus')}
|
|
50
|
-
onBlur={action('onBlur')}
|
|
51
|
-
state={inputState.inactive}
|
|
52
|
-
/>
|
|
53
|
-
)
|
|
54
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { regular, inactive } from './Input.int.story'
|
|
2
|
-
|
|
3
|
-
describe('<Input />', () => {
|
|
4
|
-
afterEach(() => jest.clearAllMocks())
|
|
5
|
-
|
|
6
|
-
describe('Render', () => {
|
|
7
|
-
test('must match regular()', () => {
|
|
8
|
-
expect(global.renderToJSON(regular())).toMatchSnapshot()
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
test('must match inactive()', () => {
|
|
12
|
-
expect(global.renderToJSON(inactive())).toMatchSnapshot()
|
|
13
|
-
})
|
|
14
|
-
})
|
|
15
|
-
})
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export const radioState = {
|
|
2
|
-
active: 'active',
|
|
3
|
-
inactive: 'inactive',
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export const inputType = {
|
|
7
|
-
radio: 'radio',
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const defaultProps = {
|
|
11
|
-
dataTest: null,
|
|
12
|
-
className: null,
|
|
13
|
-
htmlFor: 'checkbox',
|
|
14
|
-
inputType: inputType.radio,
|
|
15
|
-
isChecked: false,
|
|
16
|
-
text: null,
|
|
17
|
-
state: radioState.active,
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface RadioProps {
|
|
21
|
-
dataTest?: string
|
|
22
|
-
className?: string
|
|
23
|
-
htmlFor?: string
|
|
24
|
-
inputType?: typeof inputType.radio
|
|
25
|
-
name: string
|
|
26
|
-
isChecked?: boolean
|
|
27
|
-
text?: string
|
|
28
|
-
onChange: (value) => void
|
|
29
|
-
state?: typeof radioState.active | typeof radioState.inactive
|
|
30
|
-
}
|