@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.
Files changed (209) hide show
  1. package/build/index.js +12 -0
  2. package/build/primer/Alert/Alert.js +122 -0
  3. package/build/primer/Alert/Alert.prop.js +19 -0
  4. package/build/primer/Alert/index.js +19 -0
  5. package/build/primer/Blankslate/Blankslate.js +30 -0
  6. package/build/primer/Blankslate/Blankslate.prop.js +18 -0
  7. package/build/primer/Blankslate/index.js +19 -0
  8. package/build/primer/Breadcrumb/Breadcrumb.js +75 -0
  9. package/build/primer/Breadcrumb/Breadcrumb.prop.js +14 -0
  10. package/build/primer/Breadcrumb/index.js +19 -0
  11. package/build/primer/Button/Button.js +108 -0
  12. package/build/primer/Button/Button.prop.js +48 -0
  13. package/build/primer/Button/index.js +49 -0
  14. package/build/primer/Dropdown/Dropdown.js +102 -0
  15. package/build/primer/Dropdown/Dropdown.prop.js +18 -0
  16. package/build/primer/Dropdown/index.js +19 -0
  17. package/build/primer/ErrorBoundary/ErrorBoundary.js +59 -0
  18. package/build/primer/ErrorBoundary/ErrorBoundary.prop.js +7 -0
  19. package/build/primer/ErrorBoundary/index.js +12 -0
  20. package/build/primer/Form/Checkbox/Checkbox.js +48 -0
  21. package/build/primer/Form/Checkbox/Checkbox.prop.js +22 -0
  22. package/build/primer/Form/Checkbox/index.js +19 -0
  23. package/build/primer/Form/Input/Input.js +55 -0
  24. package/build/primer/Form/Input/Input.prop.js +27 -0
  25. package/build/primer/Form/Input/index.js +25 -0
  26. package/build/primer/Form/Radio/Radio.js +47 -0
  27. package/build/primer/Form/Radio/Radio.prop.js +22 -0
  28. package/build/primer/Form/Radio/index.js +19 -0
  29. package/build/primer/Form/index.js +24 -0
  30. package/build/primer/Grid/DisplayTable/DisplayTable.js +57 -0
  31. package/build/primer/Grid/DisplayTable/DisplayTable.prop.js +11 -0
  32. package/build/primer/Grid/DisplayTable/index.js +12 -0
  33. package/build/primer/Grid/FlexGrid/FlexGrid.js +249 -0
  34. package/build/primer/Grid/FlexGrid/FlexGrid.prop.js +28 -0
  35. package/build/primer/Grid/FlexGrid/index.js +25 -0
  36. package/build/primer/Grid/index.js +14 -0
  37. package/build/primer/Icon/Icon.js +70 -0
  38. package/build/primer/Icon/Icon.part.js +1295 -0
  39. package/build/primer/Icon/Icon.prop.js +678 -0
  40. package/build/primer/Icon/index.js +25 -0
  41. package/build/primer/Label/Label.js +30 -0
  42. package/build/primer/Label/Label.prop.js +26 -0
  43. package/build/primer/Label/index.js +12 -0
  44. package/build/primer/Loader/Loader.js +64 -0
  45. package/build/primer/Loader/Loader.prop.js +15 -0
  46. package/build/primer/Loader/index.js +19 -0
  47. package/build/primer/Navigation/Menu/Menu.js +69 -0
  48. package/build/primer/Navigation/Menu/Menu.prop.js +10 -0
  49. package/build/primer/Navigation/Menu/index.js +12 -0
  50. package/build/primer/Navigation/TabNav/TabNav.js +124 -0
  51. package/build/primer/Navigation/TabNav/TabNav.prop.js +16 -0
  52. package/build/primer/Navigation/TabNav/index.js +19 -0
  53. package/build/primer/Navigation/UnderlineNav/UnderlineNav.js +122 -0
  54. package/build/primer/Navigation/UnderlineNav/UnderlineNav.prop.js +20 -0
  55. package/build/primer/Navigation/UnderlineNav/index.js +25 -0
  56. package/build/primer/Navigation/index.js +17 -0
  57. package/build/primer/Pagination/PreviousNext/PreviousNext.js +84 -0
  58. package/build/primer/Pagination/PreviousNext/PreviousNext.prop.js +30 -0
  59. package/build/primer/Pagination/PreviousNext/index.js +19 -0
  60. package/build/primer/Pagination/index.js +11 -0
  61. package/build/primer/Popover/Popover.js +63 -0
  62. package/build/primer/Popover/Popover.prop.js +29 -0
  63. package/build/primer/Popover/index.js +25 -0
  64. package/build/primer/Progress/Progress.js +30 -0
  65. package/build/primer/Progress/Progress.prop.js +15 -0
  66. package/build/primer/Progress/index.js +19 -0
  67. package/build/primer/Select/Select.js +67 -0
  68. package/build/primer/Select/Select.prop.js +15 -0
  69. package/build/primer/Select/index.js +19 -0
  70. package/build/primer/SelectMenu/SelectMenu.js +94 -0
  71. package/build/primer/SelectMenu/SelectMenu.prop.js +10 -0
  72. package/build/primer/SelectMenu/index.js +12 -0
  73. package/build/primer/Subhead/Subhead.js +26 -0
  74. package/build/primer/Subhead/Subhead.prop.js +10 -0
  75. package/build/primer/Subhead/index.js +12 -0
  76. package/build/primer/Toast/Toast.js +54 -0
  77. package/build/primer/Toast/Toast.prop.js +18 -0
  78. package/build/primer/Toast/index.js +19 -0
  79. package/build/primer/index.js +87 -0
  80. package/package.json +5 -5
  81. package/build/index.ts +0 -1
  82. package/build/primer/Alert/Alert.prop.ts +0 -45
  83. package/build/primer/Alert/Alert.tsx +0 -101
  84. package/build/primer/Alert/__tests__/Alert.int.story.tsx +0 -86
  85. package/build/primer/Alert/__tests__/Alert.int.test.ts +0 -37
  86. package/build/primer/Alert/index.ts +0 -2
  87. package/build/primer/Blankslate/Blankslate.prop.ts +0 -26
  88. package/build/primer/Blankslate/Blankslate.tsx +0 -26
  89. package/build/primer/Blankslate/__tests__/Blankslate.int.story.tsx +0 -43
  90. package/build/primer/Blankslate/__tests__/Blankslate.int.test.ts +0 -29
  91. package/build/primer/Blankslate/index.ts +0 -2
  92. package/build/primer/Breadcrumb/Breadcrumb.prop.ts +0 -28
  93. package/build/primer/Breadcrumb/Breadcrumb.tsx +0 -57
  94. package/build/primer/Breadcrumb/__tests__/Breadcrumb.int.story.tsx +0 -40
  95. package/build/primer/Breadcrumb/__tests__/Breadcrumb.int.test.ts +0 -40
  96. package/build/primer/Breadcrumb/index.ts +0 -2
  97. package/build/primer/Button/Button.prop.ts +0 -77
  98. package/build/primer/Button/Button.tsx +0 -91
  99. package/build/primer/Button/__tests__/Button.int.story.tsx +0 -173
  100. package/build/primer/Button/__tests__/Button.int.test.ts +0 -191
  101. package/build/primer/Button/index.ts +0 -2
  102. package/build/primer/Dropdown/Dropdown.prop.ts +0 -33
  103. package/build/primer/Dropdown/Dropdown.tsx +0 -102
  104. package/build/primer/Dropdown/__tests__/Dropdown.int.story.tsx +0 -43
  105. package/build/primer/Dropdown/__tests__/Dropdown.int.test.ts +0 -53
  106. package/build/primer/Dropdown/index.ts +0 -2
  107. package/build/primer/ErrorBoundary/ErrorBoundary.prop.ts +0 -5
  108. package/build/primer/ErrorBoundary/ErrorBoundary.tsx +0 -35
  109. package/build/primer/ErrorBoundary/__tests__/ErrorBoundary.int.story.tsx +0 -23
  110. package/build/primer/ErrorBoundary/__tests__/ErrorBoundary.int.test.ts +0 -9
  111. package/build/primer/ErrorBoundary/index.ts +0 -1
  112. package/build/primer/Form/Checkbox/Checkbox.prop.ts +0 -34
  113. package/build/primer/Form/Checkbox/Checkbox.tsx +0 -40
  114. package/build/primer/Form/Checkbox/__tests__/Checkbox.int.story.tsx +0 -50
  115. package/build/primer/Form/Checkbox/__tests__/Checkbox.int.test.ts +0 -23
  116. package/build/primer/Form/Checkbox/index.ts +0 -2
  117. package/build/primer/Form/Input/Input.prop.ts +0 -43
  118. package/build/primer/Form/Input/Input.tsx +0 -43
  119. package/build/primer/Form/Input/__tests__/Input.int.story.tsx +0 -54
  120. package/build/primer/Form/Input/__tests__/Input.int.test.ts +0 -15
  121. package/build/primer/Form/Input/index.ts +0 -2
  122. package/build/primer/Form/Radio/Radio.prop.ts +0 -30
  123. package/build/primer/Form/Radio/Radio.tsx +0 -38
  124. package/build/primer/Form/Radio/__tests__/Radio.int.story.tsx +0 -42
  125. package/build/primer/Form/Radio/__tests__/Radio.int.test.ts +0 -13
  126. package/build/primer/Form/Radio/index.ts +0 -2
  127. package/build/primer/Form/index.ts +0 -19
  128. package/build/primer/Grid/DisplayTable/DisplayTable.prop.ts +0 -21
  129. package/build/primer/Grid/DisplayTable/DisplayTable.tsx +0 -68
  130. package/build/primer/Grid/DisplayTable/__tests__/DisplayTable.int.data.ts +0 -289
  131. package/build/primer/Grid/DisplayTable/__tests__/DisplayTable.int.story.tsx +0 -27
  132. package/build/primer/Grid/DisplayTable/__tests__/DisplayTable.int.test.ts +0 -9
  133. package/build/primer/Grid/DisplayTable/index.ts +0 -1
  134. package/build/primer/Grid/FlexGrid/FlexGrid.prop.ts +0 -59
  135. package/build/primer/Grid/FlexGrid/FlexGrid.tsx +0 -274
  136. package/build/primer/Grid/FlexGrid/__tests__/FlexGrid.int.data.ts +0 -289
  137. package/build/primer/Grid/FlexGrid/__tests__/FlexGrid.int.story.tsx +0 -146
  138. package/build/primer/Grid/FlexGrid/__tests__/FlexGrid.int.test.ts +0 -46
  139. package/build/primer/Grid/FlexGrid/index.ts +0 -2
  140. package/build/primer/Grid/index.ts +0 -9
  141. package/build/primer/Icon/Icon.part.ts +0 -1289
  142. package/build/primer/Icon/Icon.prop.ts +0 -1337
  143. package/build/primer/Icon/Icon.tsx +0 -49
  144. package/build/primer/Icon/__tests__/Icon.int.story.tsx +0 -58
  145. package/build/primer/Icon/__tests__/Icon.int.test.ts +0 -13
  146. package/build/primer/Icon/index.ts +0 -2
  147. package/build/primer/Label/Label.prop.ts +0 -31
  148. package/build/primer/Label/Label.tsx +0 -27
  149. package/build/primer/Label/__tests__/Label.int.story.tsx +0 -19
  150. package/build/primer/Label/__tests__/Label.int.test.ts +0 -9
  151. package/build/primer/Label/index.ts +0 -1
  152. package/build/primer/Loader/Loader.prop.ts +0 -16
  153. package/build/primer/Loader/Loader.tsx +0 -43
  154. package/build/primer/Loader/__tests__/Loader.int.story.tsx +0 -34
  155. package/build/primer/Loader/__tests__/Loader.int.test.ts +0 -21
  156. package/build/primer/Loader/index.ts +0 -2
  157. package/build/primer/Navigation/Menu/Menu.prop.ts +0 -26
  158. package/build/primer/Navigation/Menu/Menu.tsx +0 -42
  159. package/build/primer/Navigation/Menu/__tests__/Menu.int.story.tsx +0 -55
  160. package/build/primer/Navigation/Menu/__tests__/Menu.int.test.ts +0 -57
  161. package/build/primer/Navigation/Menu/index.ts +0 -1
  162. package/build/primer/Navigation/TabNav/TabNav.prop.ts +0 -39
  163. package/build/primer/Navigation/TabNav/TabNav.tsx +0 -105
  164. package/build/primer/Navigation/TabNav/__tests__/TabNav.int.story.tsx +0 -168
  165. package/build/primer/Navigation/TabNav/__tests__/TabNav.int.test.ts +0 -55
  166. package/build/primer/Navigation/TabNav/index.ts +0 -2
  167. package/build/primer/Navigation/UnderlineNav/UnderlineNav.prop.ts +0 -41
  168. package/build/primer/Navigation/UnderlineNav/UnderlineNav.tsx +0 -106
  169. package/build/primer/Navigation/UnderlineNav/__tests__/UnderlineNav.int.story.tsx +0 -140
  170. package/build/primer/Navigation/UnderlineNav/__tests__/UnderlineNav.int.test.ts +0 -81
  171. package/build/primer/Navigation/UnderlineNav/index.ts +0 -2
  172. package/build/primer/Navigation/index.ts +0 -12
  173. package/build/primer/Pagination/PreviousNext/PreviousNext.prop.ts +0 -53
  174. package/build/primer/Pagination/PreviousNext/PreviousNext.tsx +0 -71
  175. package/build/primer/Pagination/PreviousNext/__tests__/PreviousNext.int.story.tsx +0 -48
  176. package/build/primer/Pagination/PreviousNext/__tests__/PreviousNext.int.test.ts +0 -15
  177. package/build/primer/Pagination/PreviousNext/index.ts +0 -2
  178. package/build/primer/Pagination/index.ts +0 -6
  179. package/build/primer/Popover/Popover.prop.ts +0 -49
  180. package/build/primer/Popover/Popover.tsx +0 -80
  181. package/build/primer/Popover/__tests__/Popover.int.story.tsx +0 -216
  182. package/build/primer/Popover/__tests__/Popover.int.test.ts +0 -71
  183. package/build/primer/Popover/index.ts +0 -2
  184. package/build/primer/Progress/Progress.prop.ts +0 -16
  185. package/build/primer/Progress/Progress.tsx +0 -19
  186. package/build/primer/Progress/__tests__/Progress.int.story.tsx +0 -28
  187. package/build/primer/Progress/__tests__/Progress.int.test.ts +0 -17
  188. package/build/primer/Progress/index.ts +0 -2
  189. package/build/primer/Select/Select.prop.ts +0 -24
  190. package/build/primer/Select/Select.tsx +0 -58
  191. package/build/primer/Select/__tests__/Select.int.story.tsx +0 -38
  192. package/build/primer/Select/__tests__/Select.int.test.ts +0 -42
  193. package/build/primer/Select/index.ts +0 -2
  194. package/build/primer/SelectMenu/SelectMenu.prop.ts +0 -25
  195. package/build/primer/SelectMenu/SelectMenu.tsx +0 -68
  196. package/build/primer/SelectMenu/__tests__/SelectMenu.int.story.tsx +0 -50
  197. package/build/primer/SelectMenu/__tests__/SelectMenu.int.test.ts +0 -56
  198. package/build/primer/SelectMenu/index.ts +0 -1
  199. package/build/primer/Subhead/Subhead.prop.ts +0 -10
  200. package/build/primer/Subhead/Subhead.tsx +0 -15
  201. package/build/primer/Subhead/__tests__/Subhead.int.story.tsx +0 -23
  202. package/build/primer/Subhead/__tests__/Subhead.int.test.ts +0 -13
  203. package/build/primer/Subhead/index.ts +0 -1
  204. package/build/primer/Toast/Toast.prop.ts +0 -21
  205. package/build/primer/Toast/Toast.tsx +0 -38
  206. package/build/primer/Toast/__tests__/Toast.int.story.tsx +0 -50
  207. package/build/primer/Toast/__tests__/Toast.int.test.ts +0 -25
  208. package/build/primer/Toast/index.ts +0 -2
  209. package/build/primer/index.ts +0 -83
@@ -1,57 +0,0 @@
1
- /* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
2
- /* eslint-disable jsx-a11y/click-events-have-key-events */
3
- import cx from 'classnames'
4
- import { v1 as uuidv1 } from 'uuid'
5
- import utilityStyles from '@papillonarts/css/build/primer/utilities/typography.scss'
6
- import { getIndexItems, getIndexItemsWithSelected } from '@papillonarts/library/array'
7
- import { BreadcrumbProps, defaultProps, breadcrumbState } from './Breadcrumb.prop'
8
- import styles from './Breadcrumb.scss'
9
-
10
- export function Breadcrumb({ className = defaultProps.className, ariaAttr, items, onClick, state = defaultProps.state }: BreadcrumbProps) {
11
- const indexItems = getIndexItems(items)
12
- const { label, current } = ariaAttr
13
-
14
- return (
15
- <nav
16
- className={cx(className, {
17
- [styles['breadcrumb-inactive']]: state === breadcrumbState.inactive,
18
- })}
19
- aria-label={label}
20
- >
21
- <ol>
22
- {indexItems.map((indexItem) => {
23
- const { href, text, isSelected } = indexItem
24
-
25
- const itemOtherProps = isSelected ? { ...{ 'aria-current': current } } : null
26
-
27
- return (
28
- <li
29
- key={uuidv1()}
30
- onClick={(e) => {
31
- e.preventDefault()
32
- const newIndexItems = getIndexItemsWithSelected(indexItems, indexItem)
33
- onClick({
34
- active: text,
35
- ariaAttr,
36
- items: newIndexItems.map(
37
- (newIndexItem) => (({ href, text, isSelected }) => ({ href, text, isSelected }))(newIndexItem), // eslint-disable-line
38
- ),
39
- })
40
- }}
41
- className={
42
- !isSelected
43
- ? cx(styles['breadcrumb-item'])
44
- : cx(styles['breadcrumb-item'], styles['breadcrumb-item-selected'], utilityStyles['text-gray'])
45
- }
46
- // @ts-ignore
47
- href={href}
48
- {...itemOtherProps}
49
- >
50
- {isSelected ? text : <a href={href}>{text}</a>}
51
- </li>
52
- )
53
- })}
54
- </ol>
55
- </nav>
56
- )
57
- }
@@ -1,40 +0,0 @@
1
- import { action } from 'storybook/actions'
2
- import { withTests } from '@storybook/addon-jest'
3
- import { breadcrumbState } from '../Breadcrumb.prop'
4
- import results from '../../../../../../.jest-test-results.json'
5
-
6
- const Breadcrumb =
7
- process.env.NODE_ENV === 'develop' || process.env.NODE_ENV === 'test'
8
- ? require('../../../index').primer.Breadcrumb.Breadcrumb
9
- : require('../../../../build').primer.Breadcrumb.Breadcrumb
10
-
11
- export default {
12
- title: 'Primer/Atom/Breadcrumb',
13
- component: Breadcrumb,
14
- decorators: [withTests({ results })],
15
- parameters: { jest: ['Breadcrumb.int.test.js'] },
16
- excludeStories: ['ariaAttr', 'items', 'custom'],
17
- }
18
-
19
- export const ariaAttr = {
20
- label: 'Breadcrumb',
21
- current: 'page',
22
- }
23
-
24
- export const items = [
25
- { href: '/fantastic-folder', text: 'Fantastic Folder', isSelected: false },
26
- { href: '/fantastic-folder/another-fantastic-folder', text: 'Another Fantastic folder', isSelected: false },
27
- { href: '', text: 'One More Fantastic Folder', isSelected: true },
28
- ]
29
-
30
- export function custom(onClick) {
31
- return <Breadcrumb ariaAttr={ariaAttr} items={items} onClick={onClick} />
32
- }
33
-
34
- export function regular() {
35
- return <Breadcrumb ariaAttr={ariaAttr} items={items} onClick={action('onClick')} />
36
- }
37
-
38
- export function inactive() {
39
- return <Breadcrumb ariaAttr={ariaAttr} items={items} onClick={action('onClick')} state={breadcrumbState.inactive} />
40
- }
@@ -1,40 +0,0 @@
1
- import { items, regular, inactive } from './Breadcrumb.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('<Breadcrumb />', () => {
11
- const indexItemsDataObject = [
12
- { ...items[0], index: 0 },
13
- { ...items[1], index: 1 },
14
- { ...items[2], index: 2 },
15
- ]
16
-
17
- const newIndexItemsWithSelectedDataObject = [
18
- { ...items[0], index: 0, isSelected: true },
19
- { ...items[1], index: 1, isSelected: false },
20
- { ...items[2], index: 2, isSelected: false },
21
- ]
22
-
23
- beforeEach(() => {
24
- jest.spyOn(libraryArrayMockObject, 'getIndexItems').mockReturnValue(indexItemsDataObject)
25
-
26
- jest.spyOn(libraryArrayMockObject, 'getIndexItemsWithSelected').mockReturnValue(newIndexItemsWithSelectedDataObject)
27
- })
28
-
29
- afterEach(() => jest.clearAllMocks())
30
-
31
- describe('Render', () => {
32
- test('must match regular()', () => {
33
- expect(global.renderToJSON(regular())).toMatchSnapshot()
34
- })
35
-
36
- test('must match inactive()', () => {
37
- expect(global.renderToJSON(inactive())).toMatchSnapshot()
38
- })
39
- })
40
- })
@@ -1,2 +0,0 @@
1
- export { Breadcrumb } from './Breadcrumb'
2
- export { breadcrumbState } from './Breadcrumb.prop'
@@ -1,77 +0,0 @@
1
- import { IconNameType } from '../Icon/Icon.prop'
2
-
3
- export const buttonElement = {
4
- button: 'button',
5
- a: 'a',
6
- }
7
-
8
- export const buttonVariant = {
9
- default: 'default',
10
- primary: 'primary',
11
- danger: 'danger',
12
- outline: 'outline',
13
- blue: 'blue',
14
- orange: 'orange',
15
- }
16
-
17
- export const buttonSize = {
18
- small: 'small',
19
- normal: 'normal',
20
- large: 'large',
21
- }
22
-
23
- export const buttonState = {
24
- active: 'active',
25
- inactive: 'inactive',
26
- }
27
-
28
- export const iconAlignment = {
29
- left: 'left',
30
- right: 'right',
31
- }
32
-
33
- export const buttonInputType = {
34
- file: 'file',
35
- submit: 'submit',
36
- }
37
-
38
- export const defaultProps = {
39
- dataTest: null,
40
- id: null,
41
- className: null,
42
- element: buttonElement.button,
43
- href: null,
44
- variant: buttonVariant.default,
45
- size: buttonSize.normal,
46
- state: buttonState.active,
47
- icon: null,
48
- inputType: null,
49
- autoFocus: false,
50
- }
51
-
52
- export interface IconType {
53
- name?: IconNameType
54
- alignment?: typeof iconAlignment.left | typeof iconAlignment.right
55
- }
56
-
57
- export interface ButtonProps {
58
- dataTest?: string
59
- id?: string
60
- className?: string
61
- element?: typeof buttonElement.button | typeof buttonElement.a
62
- href?: string
63
- text: string
64
- variant?:
65
- | typeof buttonVariant.default
66
- | typeof buttonVariant.primary
67
- | typeof buttonVariant.danger
68
- | typeof buttonVariant.outline
69
- | typeof buttonVariant.blue
70
- | typeof buttonVariant.orange
71
- size?: typeof buttonSize.small | typeof buttonSize.normal | typeof buttonSize.large
72
- state?: typeof buttonState.active | typeof buttonState.inactive
73
- icon?: IconType
74
- onClick: (value?: string) => void
75
- inputType?: typeof buttonInputType.file | typeof buttonInputType.submit
76
- autoFocus?: boolean
77
- }
@@ -1,91 +0,0 @@
1
- import cx from 'classnames'
2
- import { useRef } from '@papillonarts/library/hooks'
3
- import utilityStyles from '@papillonarts/css/build/primer/utilities/margin.scss'
4
- import {
5
- ButtonProps,
6
- defaultProps,
7
- buttonElement,
8
- buttonVariant,
9
- buttonSize,
10
- buttonState,
11
- iconAlignment,
12
- buttonInputType,
13
- } from './Button.prop'
14
- import styles from './Button.scss'
15
- import { Icon, iconSize } from '../Icon'
16
-
17
- export function Button({
18
- dataTest = defaultProps.dataTest,
19
- id = defaultProps.id,
20
- className = defaultProps.className,
21
- element = defaultProps.element,
22
- href = defaultProps.href,
23
- text,
24
- variant = defaultProps.variant,
25
- size = defaultProps.size,
26
- state = defaultProps.state,
27
- icon = defaultProps.icon,
28
- onClick,
29
- inputType = defaultProps.inputType,
30
- autoFocus = defaultProps.autoFocus,
31
- }: ButtonProps) {
32
- const stateProps = state === buttonState.inactive ? { ...{ disabled: 'true', 'aria-disabled': 'true' } } : null
33
- const fileInputRef = useRef(null)
34
-
35
- if (element === buttonElement.button) {
36
- return (
37
- // @ts-ignore
38
- <button
39
- data-test={dataTest}
40
- id={id}
41
- className={cx(className, styles.btn, {
42
- [styles['btn-sm']]: size === buttonSize.small,
43
- [styles['btn-large']]: size === buttonSize.large,
44
- [styles['btn-primary']]: variant === buttonVariant.primary,
45
- [styles['btn-danger']]: variant === buttonVariant.danger,
46
- [styles['btn-outline']]: variant === buttonVariant.outline,
47
- [styles['btn-blue']]: variant === buttonVariant.blue,
48
- [styles['btn-orange']]: variant === buttonVariant.orange,
49
- [styles['button-inactive']]: state === buttonState.inactive,
50
- })}
51
- type="button"
52
- autoFocus={autoFocus} // eslint-disable-line
53
- onClick={() => {
54
- if (inputType === buttonInputType.file) {
55
- fileInputRef.current.click()
56
- }
57
- if (!inputType) {
58
- onClick()
59
- }
60
- }}
61
- {...stateProps}
62
- >
63
- {icon?.alignment === iconAlignment.left && <Icon className={utilityStyles['mr-2']} icon={icon.name} size={iconSize.small} />}
64
- {text}
65
- {icon?.alignment === iconAlignment.right && <Icon className={utilityStyles['ml-2']} icon={icon.name} size={iconSize.small} />}
66
- {inputType && inputType === buttonInputType.file && (
67
- <input
68
- onChange={() => {
69
- onClick(fileInputRef.current.files)
70
- }}
71
- ref={fileInputRef}
72
- type="file"
73
- autoFocus={autoFocus} // eslint-disable-line
74
- multiple
75
- style={{ display: 'none' }}
76
- />
77
- )}
78
- </button>
79
- )
80
- }
81
-
82
- // @ts-ignore
83
- if (element === buttonElement.a) {
84
- return (
85
- // @ts-ignore
86
- <a className={cx(className, styles.btn)} href={href} role="button" onClick={onClick} {...stateProps}>
87
- {text}
88
- </a>
89
- )
90
- }
91
- }
@@ -1,173 +0,0 @@
1
- import { action } from 'storybook/actions'
2
- import { withTests } from '@storybook/addon-jest'
3
- import { buttonElement, buttonVariant, buttonSize, buttonState, iconAlignment } from '../Button.prop'
4
- import { iconName } from '../../Icon/Icon.prop'
5
- import results from '../../../../../../.jest-test-results.json'
6
-
7
- const Button =
8
- process.env.NODE_ENV === 'develop' || process.env.NODE_ENV === 'test'
9
- ? require('../../../index').primer.Button.Button
10
- : require('../../../../build').primer.Button.Button
11
-
12
- const plusIconLeftAligned = { name: iconName.Plus16, alignment: iconAlignment.left }
13
- const plusIconRightAligned = { name: iconName.Plus16, alignment: iconAlignment.right }
14
-
15
- export default {
16
- title: 'Primer/Atom/Button',
17
- component: Button,
18
- decorators: [withTests({ results })],
19
- parameters: { jest: ['Button.int.test.js'] },
20
- excludeStories: ['custom'],
21
- }
22
-
23
- export function custom(element, onClick) {
24
- return <Button text="Custom button" element={element} onClick={onClick} />
25
- }
26
-
27
- export function defaultNormal() {
28
- return <Button text="Default normal button" onClick={action('onClick')} />
29
- }
30
-
31
- export function defaultSmall() {
32
- return <Button text="Default small button" size={buttonSize.small} onClick={action('onClick')} />
33
- }
34
-
35
- export function defaultLarge() {
36
- return <Button text="Default large button" size={buttonSize.large} onClick={action('onClick')} />
37
- }
38
-
39
- export function defaultInactive() {
40
- return <Button text="Default inactive button" state={buttonState.inactive} onClick={action('onClick')} />
41
- }
42
-
43
- export function defaultIconLeftAligned() {
44
- return <Button text="Default icon button" icon={plusIconLeftAligned} onClick={action('onClick')} />
45
- }
46
-
47
- export function defaultIconRightAligned() {
48
- return <Button text="Default icon button" icon={plusIconRightAligned} onClick={action('onClick')} />
49
- }
50
-
51
- export function defaultLink() {
52
- return <Button element={buttonElement.a} href="#url" text="Default link button" onClick={action('onClick')} />
53
- }
54
-
55
- export function primary() {
56
- return <Button text="Primary button" variant={buttonVariant.primary} onClick={action('onClick')} />
57
- }
58
-
59
- export function primarySmall() {
60
- return <Button text="Primary small button" variant={buttonVariant.primary} size={buttonSize.small} onClick={action('onClick')} />
61
- }
62
-
63
- export function primaryLarge() {
64
- return <Button text="Primary large button" variant={buttonVariant.primary} size={buttonSize.large} onClick={action('onClick')} />
65
- }
66
-
67
- export function primaryInactive() {
68
- return <Button text="Primary inactive button" variant={buttonVariant.primary} state={buttonState.inactive} onClick={action('onClick')} />
69
- }
70
-
71
- export function primaryIconLeftAligned() {
72
- return <Button text="Primary icon button" variant={buttonVariant.primary} icon={plusIconLeftAligned} onClick={action('onClick')} />
73
- }
74
-
75
- export function primaryIconRightAligned() {
76
- return <Button text="Primary icon button" variant={buttonVariant.primary} icon={plusIconRightAligned} onClick={action('onClick')} />
77
- }
78
-
79
- export function danger() {
80
- return <Button text="Danger button" variant={buttonVariant.danger} onClick={action('onClick')} />
81
- }
82
-
83
- export function dangerSmall() {
84
- return <Button text="Danger small button" variant={buttonVariant.danger} size={buttonSize.small} onClick={action('onClick')} />
85
- }
86
-
87
- export function dangerLarge() {
88
- return <Button text="Danger large button" variant={buttonVariant.danger} size={buttonSize.large} onClick={action('onClick')} />
89
- }
90
-
91
- export function dangerInactive() {
92
- return <Button text="Danger inactive button" variant={buttonVariant.danger} state={buttonState.inactive} onClick={action('onClick')} />
93
- }
94
-
95
- export function dangerIconLeftAligned() {
96
- return <Button text="Danger icon button" variant={buttonVariant.danger} icon={plusIconLeftAligned} onClick={action('onClick')} />
97
- }
98
-
99
- export function dangerIconRightAligned() {
100
- return <Button text="Danger icon button" variant={buttonVariant.danger} icon={plusIconRightAligned} onClick={action('onClick')} />
101
- }
102
-
103
- export function outline() {
104
- return <Button text="Outline button" variant={buttonVariant.outline} onClick={action('onClick')} />
105
- }
106
-
107
- export function outlineSmall() {
108
- return <Button text="Outline small button" variant={buttonVariant.outline} size={buttonSize.small} onClick={action('onClick')} />
109
- }
110
-
111
- export function outlineLarge() {
112
- return <Button text="Outline large button" variant={buttonVariant.outline} size={buttonSize.large} onClick={action('onClick')} />
113
- }
114
-
115
- export function outlineInactive() {
116
- return <Button text="Outline inactive button" variant={buttonVariant.outline} state={buttonState.inactive} onClick={action('onClick')} />
117
- }
118
-
119
- export function outlineIconLeftAligned() {
120
- return <Button text="Outline icon button" variant={buttonVariant.outline} icon={plusIconLeftAligned} onClick={action('onClick')} />
121
- }
122
-
123
- export function outlineIconRightAligned() {
124
- return <Button text="Outline icon button" variant={buttonVariant.outline} icon={plusIconRightAligned} onClick={action('onClick')} />
125
- }
126
-
127
- export function blue() {
128
- return <Button text="Blue button" variant={buttonVariant.blue} onClick={action('onClick')} />
129
- }
130
-
131
- export function blueSmall() {
132
- return <Button text="Blue small button" variant={buttonVariant.blue} size={buttonSize.small} onClick={action('onClick')} />
133
- }
134
-
135
- export function blueLarge() {
136
- return <Button text="Blue large button" variant={buttonVariant.blue} size={buttonSize.large} onClick={action('onClick')} />
137
- }
138
-
139
- export function blueInactive() {
140
- return <Button text="Blue inactive button" variant={buttonVariant.blue} state={buttonState.inactive} onClick={action('onClick')} />
141
- }
142
-
143
- export function blueIconLeftAligned() {
144
- return <Button text="Blue icon button" variant={buttonVariant.blue} icon={plusIconLeftAligned} onClick={action('onClick')} />
145
- }
146
-
147
- export function blueIconRightAligned() {
148
- return <Button text="Blue icon button" variant={buttonVariant.blue} icon={plusIconRightAligned} onClick={action('onClick')} />
149
- }
150
-
151
- export function orange() {
152
- return <Button text="Orange button" variant={buttonVariant.orange} onClick={action('onClick')} />
153
- }
154
-
155
- export function orangeSmall() {
156
- return <Button text="Orange small button" variant={buttonVariant.orange} size={buttonSize.small} onClick={action('onClick')} />
157
- }
158
-
159
- export function orangeLarge() {
160
- return <Button text="Orange large button" variant={buttonVariant.orange} size={buttonSize.large} onClick={action('onClick')} />
161
- }
162
-
163
- export function orangeInactive() {
164
- return <Button text="Orange inactive button" variant={buttonVariant.orange} state={buttonState.inactive} onClick={action('onClick')} />
165
- }
166
-
167
- export function orangeIconLeftAligned() {
168
- return <Button text="Orange icon button" variant={buttonVariant.orange} icon={plusIconLeftAligned} onClick={action('onClick')} />
169
- }
170
-
171
- export function orangeIconRightAligned() {
172
- return <Button text="Orange icon button" variant={buttonVariant.orange} icon={plusIconRightAligned} onClick={action('onClick')} />
173
- }
@@ -1,191 +0,0 @@
1
- import {
2
- defaultNormal,
3
- defaultSmall,
4
- defaultLarge,
5
- defaultInactive,
6
- defaultIconLeftAligned,
7
- defaultIconRightAligned,
8
- defaultLink,
9
- primary,
10
- primarySmall,
11
- primaryLarge,
12
- primaryInactive,
13
- primaryIconLeftAligned,
14
- primaryIconRightAligned,
15
- danger,
16
- dangerSmall,
17
- dangerLarge,
18
- dangerInactive,
19
- dangerIconLeftAligned,
20
- dangerIconRightAligned,
21
- outline,
22
- outlineSmall,
23
- outlineLarge,
24
- outlineInactive,
25
- outlineIconLeftAligned,
26
- outlineIconRightAligned,
27
- blue,
28
- blueSmall,
29
- blueLarge,
30
- blueInactive,
31
- blueIconLeftAligned,
32
- blueIconRightAligned,
33
- orange,
34
- orangeSmall,
35
- orangeLarge,
36
- orangeInactive,
37
- orangeIconLeftAligned,
38
- orangeIconRightAligned,
39
- } from './Button.int.story'
40
-
41
- describe('<Button />', () => {
42
- describe('Render', () => {
43
- test('must match defaultNormal()', () => {
44
- expect(global.renderToJSON(defaultNormal())).toMatchSnapshot()
45
- })
46
-
47
- test('must match defaultSmall()', () => {
48
- expect(global.renderToJSON(defaultSmall())).toMatchSnapshot()
49
- })
50
-
51
- test('must match defaultLarge()', () => {
52
- expect(global.renderToJSON(defaultLarge())).toMatchSnapshot()
53
- })
54
-
55
- test('must match defaultInactive()', () => {
56
- expect(global.renderToJSON(defaultInactive())).toMatchSnapshot()
57
- })
58
-
59
- test('must match defaultIconLeftAligned()', () => {
60
- expect(global.renderToJSON(defaultIconLeftAligned())).toMatchSnapshot()
61
- })
62
-
63
- test('must match defaultIconRightAligned()', () => {
64
- expect(global.renderToJSON(defaultIconRightAligned())).toMatchSnapshot()
65
- })
66
-
67
- test('must match defaultLink()', () => {
68
- expect(global.renderToJSON(defaultLink())).toMatchSnapshot()
69
- })
70
-
71
- test('must match primary()', () => {
72
- expect(global.renderToJSON(primary())).toMatchSnapshot()
73
- })
74
-
75
- test('must match primarySmall()', () => {
76
- expect(global.renderToJSON(primarySmall())).toMatchSnapshot()
77
- })
78
-
79
- test('must match primaryLarge()', () => {
80
- expect(global.renderToJSON(primaryLarge())).toMatchSnapshot()
81
- })
82
-
83
- test('must match primaryInactive()', () => {
84
- expect(global.renderToJSON(primaryInactive())).toMatchSnapshot()
85
- })
86
-
87
- test('must match primaryIconLeftAligned()', () => {
88
- expect(global.renderToJSON(primaryIconLeftAligned())).toMatchSnapshot()
89
- })
90
-
91
- test('must match primaryIconRightAligned()', () => {
92
- expect(global.renderToJSON(primaryIconRightAligned())).toMatchSnapshot()
93
- })
94
-
95
- test('must match danger()', () => {
96
- expect(global.renderToJSON(danger())).toMatchSnapshot()
97
- })
98
-
99
- test('must match dangerSmall()', () => {
100
- expect(global.renderToJSON(dangerSmall())).toMatchSnapshot()
101
- })
102
-
103
- test('must match dangerLarge()', () => {
104
- expect(global.renderToJSON(dangerLarge())).toMatchSnapshot()
105
- })
106
-
107
- test('must match dangerInactive()', () => {
108
- expect(global.renderToJSON(dangerInactive())).toMatchSnapshot()
109
- })
110
-
111
- test('must match dangerIconLeftAligned()', () => {
112
- expect(global.renderToJSON(dangerIconLeftAligned())).toMatchSnapshot()
113
- })
114
-
115
- test('must match dangerIconRightAligned()', () => {
116
- expect(global.renderToJSON(dangerIconRightAligned())).toMatchSnapshot()
117
- })
118
-
119
- test('must match outline()', () => {
120
- expect(global.renderToJSON(outline())).toMatchSnapshot()
121
- })
122
-
123
- test('must match outlineSmall()', () => {
124
- expect(global.renderToJSON(outlineSmall())).toMatchSnapshot()
125
- })
126
-
127
- test('must match outlineLarge()', () => {
128
- expect(global.renderToJSON(outlineLarge())).toMatchSnapshot()
129
- })
130
-
131
- test('must match outlineInactive()', () => {
132
- expect(global.renderToJSON(outlineInactive())).toMatchSnapshot()
133
- })
134
-
135
- test('must match outlineIconLeftAligned()', () => {
136
- expect(global.renderToJSON(outlineIconLeftAligned())).toMatchSnapshot()
137
- })
138
-
139
- test('must match outlineIconRightAligned()', () => {
140
- expect(global.renderToJSON(outlineIconRightAligned())).toMatchSnapshot()
141
- })
142
-
143
- test('must match blue()', () => {
144
- expect(global.renderToJSON(blue())).toMatchSnapshot()
145
- })
146
-
147
- test('must match blueSmall()', () => {
148
- expect(global.renderToJSON(blueSmall())).toMatchSnapshot()
149
- })
150
-
151
- test('must match blueLarge()', () => {
152
- expect(global.renderToJSON(blueLarge())).toMatchSnapshot()
153
- })
154
-
155
- test('must match blueInactive()', () => {
156
- expect(global.renderToJSON(blueInactive())).toMatchSnapshot()
157
- })
158
-
159
- test('must match blueIconLeftAligned()', () => {
160
- expect(global.renderToJSON(blueIconLeftAligned())).toMatchSnapshot()
161
- })
162
-
163
- test('must match blueIconRightAligned()', () => {
164
- expect(global.renderToJSON(blueIconRightAligned())).toMatchSnapshot()
165
- })
166
-
167
- test('must match orange()', () => {
168
- expect(global.renderToJSON(orange())).toMatchSnapshot()
169
- })
170
-
171
- test('must match orangeSmall()', () => {
172
- expect(global.renderToJSON(orangeSmall())).toMatchSnapshot()
173
- })
174
-
175
- test('must match orangeLarge()', () => {
176
- expect(global.renderToJSON(orangeLarge())).toMatchSnapshot()
177
- })
178
-
179
- test('must match orangeInactive()', () => {
180
- expect(global.renderToJSON(orangeInactive())).toMatchSnapshot()
181
- })
182
-
183
- test('must match orangeIconLeftAligned()', () => {
184
- expect(global.renderToJSON(orangeIconLeftAligned())).toMatchSnapshot()
185
- })
186
-
187
- test('must match orangeIconRightAligned()', () => {
188
- expect(global.renderToJSON(orangeIconRightAligned())).toMatchSnapshot()
189
- })
190
- })
191
- })
@@ -1,2 +0,0 @@
1
- export { Button } from './Button'
2
- export { buttonElement, buttonVariant, buttonSize, buttonState, iconAlignment, buttonInputType } from './Button.prop'