@instructure/ui-list 11.6.0 → 11.6.1-snapshot-129

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 (159) hide show
  1. package/CHANGELOG.md +38 -288
  2. package/es/InlineList/{InlineListItem → v1/InlineListItem}/index.js +2 -2
  3. package/es/InlineList/{index.js → v1/index.js} +1 -1
  4. package/es/InlineList/v2/InlineListItem/index.js +97 -0
  5. package/es/InlineList/v2/InlineListItem/styles.js +143 -0
  6. package/es/InlineList/v2/index.js +93 -0
  7. package/es/{index.js → InlineList/v2/props.js} +3 -3
  8. package/es/List/{ListItem → v1/ListItem}/index.js +2 -2
  9. package/es/List/v1/ListItem/props.js +28 -0
  10. package/es/List/{index.js → v1/index.js} +2 -2
  11. package/es/List/v2/ListItem/index.js +91 -0
  12. package/es/List/v2/ListItem/props.js +28 -0
  13. package/es/List/v2/ListItem/styles.js +131 -0
  14. package/es/List/v2/index.js +100 -0
  15. package/es/List/v2/props.js +26 -0
  16. package/es/List/v2/styles.js +66 -0
  17. package/es/exports/a.js +26 -0
  18. package/es/exports/b.js +26 -0
  19. package/lib/InlineList/{InlineListItem → v1/InlineListItem}/index.js +3 -3
  20. package/lib/InlineList/{index.js → v1/index.js} +2 -2
  21. package/lib/InlineList/v2/InlineListItem/index.js +102 -0
  22. package/lib/InlineList/v2/InlineListItem/styles.js +149 -0
  23. package/lib/InlineList/v2/index.js +101 -0
  24. package/lib/InlineList/v2/props.js +31 -0
  25. package/lib/List/{ListItem → v1/ListItem}/index.js +3 -3
  26. package/lib/List/v1/ListItem/props.js +33 -0
  27. package/lib/List/v1/index.js +114 -0
  28. package/lib/List/v2/ListItem/index.js +96 -0
  29. package/lib/List/v2/ListItem/props.js +33 -0
  30. package/lib/List/v2/ListItem/styles.js +137 -0
  31. package/lib/List/{index.js → v2/index.js} +4 -5
  32. package/lib/List/v2/props.js +31 -0
  33. package/lib/List/v2/styles.js +72 -0
  34. package/lib/{index.js → exports/a.js} +6 -6
  35. package/lib/exports/b.js +32 -0
  36. package/package.json +39 -17
  37. package/src/InlineList/{InlineListItem → v1/InlineListItem}/index.tsx +2 -2
  38. package/src/InlineList/{index.tsx → v1/index.tsx} +1 -1
  39. package/src/InlineList/v2/InlineListItem/index.tsx +110 -0
  40. package/src/InlineList/v2/InlineListItem/props.ts +99 -0
  41. package/src/InlineList/v2/InlineListItem/styles.ts +142 -0
  42. package/src/InlineList/v2/README.md +146 -0
  43. package/src/InlineList/v2/index.tsx +102 -0
  44. package/src/InlineList/v2/props.ts +80 -0
  45. package/src/List/{ListItem → v1/ListItem}/index.tsx +2 -2
  46. package/src/List/{index.tsx → v1/index.tsx} +2 -2
  47. package/src/List/v2/ListItem/index.tsx +104 -0
  48. package/src/List/v2/ListItem/props.ts +94 -0
  49. package/src/List/v2/ListItem/styles.ts +136 -0
  50. package/src/List/v2/README.md +142 -0
  51. package/src/List/v2/index.tsx +109 -0
  52. package/src/List/v2/props.ts +95 -0
  53. package/src/List/v2/styles.ts +77 -0
  54. package/src/exports/a.ts +32 -0
  55. package/src/exports/b.ts +32 -0
  56. package/tsconfig.build.tsbuildinfo +1 -1
  57. package/types/InlineList/v1/InlineListItem/index.d.ts.map +1 -0
  58. package/types/InlineList/v1/InlineListItem/props.d.ts.map +1 -0
  59. package/types/InlineList/v1/InlineListItem/styles.d.ts.map +1 -0
  60. package/types/InlineList/v1/InlineListItem/theme.d.ts.map +1 -0
  61. package/types/InlineList/v1/index.d.ts.map +1 -0
  62. package/types/InlineList/v1/props.d.ts.map +1 -0
  63. package/types/InlineList/v2/InlineListItem/index.d.ts +27 -0
  64. package/types/InlineList/v2/InlineListItem/index.d.ts.map +1 -0
  65. package/types/InlineList/v2/InlineListItem/props.d.ts +42 -0
  66. package/types/InlineList/v2/InlineListItem/props.d.ts.map +1 -0
  67. package/types/InlineList/v2/InlineListItem/styles.d.ts +14 -0
  68. package/types/InlineList/v2/InlineListItem/styles.d.ts.map +1 -0
  69. package/types/InlineList/v2/index.d.ts +35 -0
  70. package/types/InlineList/v2/index.d.ts.map +1 -0
  71. package/types/InlineList/v2/props.d.ts +33 -0
  72. package/types/InlineList/v2/props.d.ts.map +1 -0
  73. package/types/List/v1/ListItem/index.d.ts.map +1 -0
  74. package/types/List/v1/ListItem/props.d.ts.map +1 -0
  75. package/types/List/v1/ListItem/styles.d.ts.map +1 -0
  76. package/types/List/v1/ListItem/theme.d.ts.map +1 -0
  77. package/types/List/v1/index.d.ts.map +1 -0
  78. package/types/List/v1/props.d.ts.map +1 -0
  79. package/types/List/v1/styles.d.ts.map +1 -0
  80. package/types/List/v1/theme.d.ts.map +1 -0
  81. package/types/List/v2/ListItem/index.d.ts +26 -0
  82. package/types/List/v2/ListItem/index.d.ts.map +1 -0
  83. package/types/List/v2/ListItem/props.d.ts +38 -0
  84. package/types/List/v2/ListItem/props.d.ts.map +1 -0
  85. package/types/List/v2/ListItem/styles.d.ts +14 -0
  86. package/types/List/v2/ListItem/styles.d.ts.map +1 -0
  87. package/types/List/v2/index.d.ts +38 -0
  88. package/types/List/v2/index.d.ts.map +1 -0
  89. package/types/List/v2/props.d.ts +41 -0
  90. package/types/List/v2/props.d.ts.map +1 -0
  91. package/types/List/v2/styles.d.ts +15 -0
  92. package/types/List/v2/styles.d.ts.map +1 -0
  93. package/types/exports/a.d.ts +8 -0
  94. package/types/exports/a.d.ts.map +1 -0
  95. package/types/exports/b.d.ts +8 -0
  96. package/types/exports/b.d.ts.map +1 -0
  97. package/src/index.ts +0 -32
  98. package/types/InlineList/InlineListItem/index.d.ts.map +0 -1
  99. package/types/InlineList/InlineListItem/props.d.ts.map +0 -1
  100. package/types/InlineList/InlineListItem/styles.d.ts.map +0 -1
  101. package/types/InlineList/InlineListItem/theme.d.ts.map +0 -1
  102. package/types/InlineList/index.d.ts.map +0 -1
  103. package/types/InlineList/props.d.ts.map +0 -1
  104. package/types/List/ListItem/index.d.ts.map +0 -1
  105. package/types/List/ListItem/props.d.ts.map +0 -1
  106. package/types/List/ListItem/styles.d.ts.map +0 -1
  107. package/types/List/ListItem/theme.d.ts.map +0 -1
  108. package/types/List/index.d.ts.map +0 -1
  109. package/types/List/props.d.ts.map +0 -1
  110. package/types/List/styles.d.ts.map +0 -1
  111. package/types/List/theme.d.ts.map +0 -1
  112. package/types/index.d.ts +0 -8
  113. package/types/index.d.ts.map +0 -1
  114. /package/es/InlineList/{InlineListItem → v1/InlineListItem}/props.js +0 -0
  115. /package/es/InlineList/{InlineListItem → v1/InlineListItem}/styles.js +0 -0
  116. /package/es/InlineList/{InlineListItem → v1/InlineListItem}/theme.js +0 -0
  117. /package/es/InlineList/{props.js → v1/props.js} +0 -0
  118. /package/es/{List/ListItem → InlineList/v2/InlineListItem}/props.js +0 -0
  119. /package/es/List/{ListItem → v1/ListItem}/styles.js +0 -0
  120. /package/es/List/{ListItem → v1/ListItem}/theme.js +0 -0
  121. /package/es/List/{props.js → v1/props.js} +0 -0
  122. /package/es/List/{styles.js → v1/styles.js} +0 -0
  123. /package/es/List/{theme.js → v1/theme.js} +0 -0
  124. /package/lib/InlineList/{InlineListItem → v1/InlineListItem}/props.js +0 -0
  125. /package/lib/InlineList/{InlineListItem → v1/InlineListItem}/styles.js +0 -0
  126. /package/lib/InlineList/{InlineListItem → v1/InlineListItem}/theme.js +0 -0
  127. /package/lib/InlineList/{props.js → v1/props.js} +0 -0
  128. /package/lib/{List/ListItem → InlineList/v2/InlineListItem}/props.js +0 -0
  129. /package/lib/List/{ListItem → v1/ListItem}/styles.js +0 -0
  130. /package/lib/List/{ListItem → v1/ListItem}/theme.js +0 -0
  131. /package/lib/List/{props.js → v1/props.js} +0 -0
  132. /package/lib/List/{styles.js → v1/styles.js} +0 -0
  133. /package/lib/List/{theme.js → v1/theme.js} +0 -0
  134. /package/src/InlineList/{InlineListItem → v1/InlineListItem}/props.ts +0 -0
  135. /package/src/InlineList/{InlineListItem → v1/InlineListItem}/styles.ts +0 -0
  136. /package/src/InlineList/{InlineListItem → v1/InlineListItem}/theme.ts +0 -0
  137. /package/src/InlineList/{README.md → v1/README.md} +0 -0
  138. /package/src/InlineList/{props.ts → v1/props.ts} +0 -0
  139. /package/src/List/{ListItem → v1/ListItem}/props.ts +0 -0
  140. /package/src/List/{ListItem → v1/ListItem}/styles.ts +0 -0
  141. /package/src/List/{ListItem → v1/ListItem}/theme.ts +0 -0
  142. /package/src/List/{README.md → v1/README.md} +0 -0
  143. /package/src/List/{props.ts → v1/props.ts} +0 -0
  144. /package/src/List/{styles.ts → v1/styles.ts} +0 -0
  145. /package/src/List/{theme.ts → v1/theme.ts} +0 -0
  146. /package/types/InlineList/{InlineListItem → v1/InlineListItem}/index.d.ts +0 -0
  147. /package/types/InlineList/{InlineListItem → v1/InlineListItem}/props.d.ts +0 -0
  148. /package/types/InlineList/{InlineListItem → v1/InlineListItem}/styles.d.ts +0 -0
  149. /package/types/InlineList/{InlineListItem → v1/InlineListItem}/theme.d.ts +0 -0
  150. /package/types/InlineList/{index.d.ts → v1/index.d.ts} +0 -0
  151. /package/types/InlineList/{props.d.ts → v1/props.d.ts} +0 -0
  152. /package/types/List/{ListItem → v1/ListItem}/index.d.ts +0 -0
  153. /package/types/List/{ListItem → v1/ListItem}/props.d.ts +0 -0
  154. /package/types/List/{ListItem → v1/ListItem}/styles.d.ts +0 -0
  155. /package/types/List/{ListItem → v1/ListItem}/theme.d.ts +0 -0
  156. /package/types/List/{index.d.ts → v1/index.d.ts} +0 -0
  157. /package/types/List/{props.d.ts → v1/props.d.ts} +0 -0
  158. /package/types/List/{styles.d.ts → v1/styles.d.ts} +0 -0
  159. /package/types/List/{theme.d.ts → v1/theme.d.ts} +0 -0
@@ -0,0 +1,102 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ import { Children, Component, ReactElement } from 'react'
25
+
26
+ import { View } from '@instructure/ui-view/latest'
27
+ import { passthroughProps, safeCloneElement } from '@instructure/ui-react-utils'
28
+
29
+ import { InlineListItem } from './InlineListItem'
30
+
31
+ import { allowedProps } from './props'
32
+ import type { InlineListProps } from './props'
33
+
34
+ /**
35
+ ---
36
+ category: components
37
+ ---
38
+
39
+ **/
40
+ class InlineList extends Component<InlineListProps> {
41
+ static allowedProps = allowedProps
42
+ static defaultProps = {
43
+ itemSpacing: 'none',
44
+ as: 'ul',
45
+ margin: 'none',
46
+ delimiter: 'none',
47
+ size: 'medium'
48
+ }
49
+
50
+ static Item = InlineListItem
51
+
52
+ ref: Element | null = null
53
+
54
+ handleRef = (el: Element | null) => {
55
+ const { elementRef } = this.props
56
+
57
+ this.ref = el
58
+
59
+ if (typeof elementRef === 'function') {
60
+ elementRef(el)
61
+ }
62
+ }
63
+
64
+ renderChildren() {
65
+ const childrenArray = Children.toArray(this.props.children)
66
+ const lastIndex = childrenArray.length - 1
67
+
68
+ return childrenArray.map((child, index) => {
69
+ if (!child) return null
70
+
71
+ const shouldRenderPlaceholder = index === lastIndex
72
+
73
+ return safeCloneElement(child as ReactElement, {
74
+ delimiter: this.props.delimiter,
75
+ size: this.props.size,
76
+ spacing: this.props.itemSpacing,
77
+ lastPlaceholder: shouldRenderPlaceholder
78
+ })
79
+ })
80
+ }
81
+
82
+ render() {
83
+ const { as, margin, elementRef, ...rest } = this.props
84
+
85
+ return (
86
+ <View
87
+ {...passthroughProps(rest)}
88
+ as={as}
89
+ margin={margin}
90
+ padding="0"
91
+ elementRef={this.handleRef}
92
+ display="block"
93
+ data-cid="InlineList"
94
+ >
95
+ {this.renderChildren()}
96
+ </View>
97
+ )
98
+ }
99
+ }
100
+
101
+ export default InlineList
102
+ export { InlineList }
@@ -0,0 +1,80 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import React from 'react'
26
+ import type { Spacing } from '@instructure/emotion'
27
+ import type { OtherHTMLAttributes } from '@instructure/shared-types'
28
+
29
+ type InlineListOwnProps = {
30
+ /**
31
+ * Only accepts `<InlineList.Item>` as a child
32
+ */
33
+ //TODO type children better e.g.:ChildrenPropTypes.oneOf([InlineListItem])
34
+ children?: React.ReactNode
35
+ as?: 'ul' | 'ol'
36
+ /**
37
+ * Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
38
+ * `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
39
+ * familiar CSS-like shorthand. For example: `margin="small auto large"`.
40
+ */
41
+ margin?: Spacing
42
+ size?: 'small' | 'medium' | 'large'
43
+ delimiter?: 'none' | 'pipe' | 'slash' | 'arrow'
44
+ /**
45
+ * Sets the margin separating each ListItem.
46
+ */
47
+ itemSpacing?:
48
+ | 'none'
49
+ | 'xxx-small'
50
+ | 'xx-small'
51
+ | 'x-small'
52
+ | 'small'
53
+ | 'medium'
54
+ | 'large'
55
+ | 'x-large'
56
+ | 'xx-large'
57
+ /**
58
+ * provides a reference to the underlying html root element
59
+ */
60
+ elementRef?: (element: Element | null) => void
61
+ }
62
+
63
+ type PropKeys = keyof InlineListOwnProps
64
+
65
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
66
+
67
+ type InlineListProps = InlineListOwnProps &
68
+ OtherHTMLAttributes<InlineListOwnProps>
69
+ const allowedProps: AllowedPropKeys = [
70
+ 'children',
71
+ 'as',
72
+ 'margin',
73
+ 'size',
74
+ 'delimiter',
75
+ 'itemSpacing',
76
+ 'elementRef'
77
+ ]
78
+
79
+ export type { InlineListProps }
80
+ export { allowedProps }
@@ -24,10 +24,10 @@
24
24
 
25
25
  import { Component } from 'react'
26
26
 
27
- import { View } from '@instructure/ui-view'
27
+ import { View } from '@instructure/ui-view/v11_6'
28
28
  import { passthroughProps } from '@instructure/ui-react-utils'
29
29
 
30
- import { withStyle } from '@instructure/emotion'
30
+ import { withStyleLegacy as withStyle } from '@instructure/emotion'
31
31
 
32
32
  import generateStyle from './styles'
33
33
  import generateComponentTheme from './theme'
@@ -24,12 +24,12 @@
24
24
 
25
25
  import { Children, Component, ReactElement } from 'react'
26
26
 
27
- import { View } from '@instructure/ui-view'
27
+ import { View } from '@instructure/ui-view/v11_6'
28
28
  import { passthroughProps, safeCloneElement } from '@instructure/ui-react-utils'
29
29
 
30
30
  import { ListItem } from './ListItem'
31
31
 
32
- import { withStyle } from '@instructure/emotion'
32
+ import { withStyleLegacy as withStyle } from '@instructure/emotion'
33
33
 
34
34
  import generateStyle from './styles'
35
35
  import generateComponentTheme from './theme'
@@ -0,0 +1,104 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { Component } from 'react'
26
+
27
+ import { View } from '@instructure/ui-view/latest'
28
+ import { passthroughProps } from '@instructure/ui-react-utils'
29
+ import { withStyle } from '@instructure/emotion'
30
+
31
+ import generateStyle from './styles'
32
+ import { allowedProps } from './props'
33
+ import type { ListItemProps } from './props'
34
+
35
+ /**
36
+ ---
37
+ parent: List
38
+ id: List.Item
39
+ ---
40
+ **/
41
+ @withStyle(generateStyle)
42
+ class ListItem extends Component<ListItemProps> {
43
+ static readonly componentId = 'List.Item'
44
+
45
+ static allowedProps = allowedProps
46
+ static defaultProps = {
47
+ padding: 'none',
48
+ spacing: 'none',
49
+ delimiter: 'none',
50
+ size: 'medium'
51
+ }
52
+
53
+ ref: Element | null = null
54
+
55
+ handleRef = (el: Element | null) => {
56
+ const { elementRef } = this.props
57
+
58
+ this.ref = el
59
+
60
+ if (typeof elementRef === 'function') {
61
+ elementRef(el)
62
+ }
63
+ }
64
+
65
+ componentDidMount() {
66
+ this.props.makeStyles?.()
67
+ }
68
+
69
+ componentDidUpdate() {
70
+ this.props.makeStyles?.()
71
+ }
72
+
73
+ render() {
74
+ const {
75
+ delimiter,
76
+ spacing,
77
+ size,
78
+ margin,
79
+ padding,
80
+ elementRef,
81
+ children,
82
+ styles,
83
+ ...rest
84
+ } = this.props
85
+
86
+ return (
87
+ <View
88
+ {...passthroughProps(rest)}
89
+ css={styles?.listItem}
90
+ as="li"
91
+ margin={margin}
92
+ padding={padding}
93
+ maxWidth="100%"
94
+ elementRef={this.handleRef}
95
+ data-cid="ListItem"
96
+ >
97
+ {children}
98
+ </View>
99
+ )
100
+ }
101
+ }
102
+
103
+ export default ListItem
104
+ export { ListItem }
@@ -0,0 +1,94 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { PropsWithChildren } from 'react'
26
+
27
+ import type {
28
+ Spacing,
29
+ WithStyleProps,
30
+ ComponentStyle
31
+ } from '@instructure/emotion'
32
+ import type {
33
+ ListItemTheme,
34
+ OtherHTMLAttributes
35
+ } from '@instructure/shared-types'
36
+
37
+ type ListItemOwnProps = {
38
+ /**
39
+ * Inherits delimiter from the parent List component.
40
+ */
41
+ delimiter?: 'none' | 'dashed' | 'solid'
42
+ size?: 'small' | 'medium' | 'large'
43
+ /**
44
+ * Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
45
+ * `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
46
+ * familiar CSS-like shorthand. For example: `margin="small auto large"`.
47
+ */
48
+ margin?: Spacing
49
+ /**
50
+ * Valid values are `0`, `none`, `xxx-small`, `xx-small`, `x-small`,
51
+ * `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
52
+ * familiar CSS-like shorthand. For example: `padding="small x-large large"`.
53
+ */
54
+ padding?: Spacing
55
+ /**
56
+ * Inherits itemSpacing from the parent List component
57
+ */
58
+ spacing?:
59
+ | 'none'
60
+ | 'xxx-small'
61
+ | 'xx-small'
62
+ | 'x-small'
63
+ | 'small'
64
+ | 'medium'
65
+ | 'large'
66
+ | 'x-large'
67
+ | 'xx-large'
68
+ /**
69
+ * provides a reference to the underlying html root element
70
+ */
71
+ elementRef?: (element: Element | null) => void
72
+ } & PropsWithChildren<unknown> // <unknown> is needed for React 17 compatibility
73
+
74
+ type PropKeys = keyof ListItemOwnProps
75
+
76
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
77
+
78
+ type ListItemProps = ListItemOwnProps &
79
+ WithStyleProps<ListItemTheme, ListItemStyle> &
80
+ OtherHTMLAttributes<ListItemOwnProps>
81
+
82
+ type ListItemStyle = ComponentStyle<'listItem'>
83
+ const allowedProps: AllowedPropKeys = [
84
+ 'children',
85
+ 'delimiter',
86
+ 'size',
87
+ 'margin',
88
+ 'padding',
89
+ 'spacing',
90
+ 'elementRef'
91
+ ]
92
+
93
+ export type { ListItemProps, ListItemStyle }
94
+ export { allowedProps }
@@ -0,0 +1,136 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { logError as error } from '@instructure/console'
26
+ import type { NewComponentTypes } from '@instructure/ui-themes'
27
+ import type { ListItemProps, ListItemStyle } from './props'
28
+
29
+ /**
30
+ * ---
31
+ * private: true
32
+ * ---
33
+ * Generates the style object from the theme and provided additional information
34
+ * @param {Object} componentTheme The theme variable object.
35
+ * @param {Object} props the props of the component, the style is applied to
36
+ * @return {Object} The final style object, which will be used in the component
37
+ */
38
+ const generateStyle = (
39
+ componentTheme: NewComponentTypes['ListItem'],
40
+ props: ListItemProps
41
+ ): ListItemStyle => {
42
+ const { size, delimiter, spacing } = props
43
+
44
+ const withDelimiter = delimiter !== 'none'
45
+ const withSpacing = spacing !== 'none'
46
+
47
+ error(
48
+ !(withDelimiter && withSpacing),
49
+ `[List] \`itemSpacing\` has no effect inside Lists with the \`delimiter\` prop set to anything other than \`none\`.`
50
+ )
51
+
52
+ const sizeVariants = {
53
+ small: { fontSize: componentTheme.fontSizeSmall },
54
+ medium: { fontSize: componentTheme.fontSizeMedium },
55
+ large: { fontSize: componentTheme.fontSizeLarge }
56
+ }
57
+
58
+ const spacingVariants = {
59
+ 'xxx-small': {
60
+ marginTop: componentTheme.spacingXXXSmall,
61
+ marginBottom: componentTheme.spacingXXXSmall
62
+ },
63
+ 'xx-small': {
64
+ marginTop: componentTheme.spacingXXSmall,
65
+ marginBottom: componentTheme.spacingXXSmall
66
+ },
67
+ 'x-small': {
68
+ marginTop: componentTheme.spacingXSmall,
69
+ marginBottom: componentTheme.spacingXSmall
70
+ },
71
+ small: {
72
+ marginTop: componentTheme.spacingSmall,
73
+ marginBottom: componentTheme.spacingSmall
74
+ },
75
+ medium: {
76
+ marginTop: componentTheme.spacingMedium,
77
+ marginBottom: componentTheme.spacingMedium
78
+ },
79
+ large: {
80
+ marginTop: componentTheme.spacingLarge,
81
+ marginBottom: componentTheme.spacingLarge
82
+ },
83
+ 'x-large': {
84
+ marginTop: componentTheme.spacingXLarge,
85
+ marginBottom: componentTheme.spacingXLarge
86
+ },
87
+ 'xx-large': {
88
+ marginTop: componentTheme.spacingXXLarge,
89
+ marginBottom: componentTheme.spacingXXLarge
90
+ },
91
+ none: {}
92
+ }
93
+
94
+ const delimiterVariants = {
95
+ dashed: {
96
+ listStylePosition: 'inside',
97
+ '&:not(:first-of-type)': {
98
+ borderTop: `
99
+ ${componentTheme.delimiterDashedBorder.width}
100
+ ${componentTheme.delimiterDashedBorder.style}
101
+ ${componentTheme.delimiterDashedBorder.color}
102
+ `
103
+ }
104
+ },
105
+ solid: {
106
+ listStylePosition: 'inside',
107
+ '&:not(:first-of-type)': {
108
+ borderTop: `
109
+ ${componentTheme.delimiterSolidBorder.width}
110
+ ${componentTheme.delimiterSolidBorder.style}
111
+ ${componentTheme.delimiterSolidBorder.color}
112
+ `
113
+ }
114
+ },
115
+ none: {}
116
+ }
117
+
118
+ return {
119
+ listItem: {
120
+ label: 'listItem',
121
+ fontWeight: componentTheme.fontWeight,
122
+ fontFamily: componentTheme.fontFamily,
123
+ lineHeight: componentTheme.lineHeight,
124
+ color: componentTheme.color,
125
+ padding: 0,
126
+ ...sizeVariants[size!],
127
+ ...(withSpacing && !withDelimiter && spacingVariants[spacing!]),
128
+ ...(withDelimiter && delimiterVariants[delimiter!]),
129
+
130
+ '&:first-of-type': { marginTop: '0' },
131
+ '&:last-of-type': { marginBottom: '0' }
132
+ }
133
+ }
134
+ }
135
+
136
+ export default generateStyle
@@ -0,0 +1,142 @@
1
+ ---
2
+ describes: List
3
+ ---
4
+
5
+ > ### What about 'inline' lists?
6
+ >
7
+ > For inline lists use the [InlineList](InlineList) component.
8
+
9
+ `<List>` accepts only `<List.Item>` as a child.
10
+
11
+ ```js
12
+ ---
13
+ type: example
14
+ ---
15
+ <div>
16
+ <List margin="0 0 medium">
17
+ <List.Item>List item 1</List.Item>
18
+ <List.Item>List item 2</List.Item>
19
+ <List.Item>List item 3</List.Item>
20
+ </List>
21
+ <List as="ol" margin="0 0 medium">
22
+ <List.Item>List item 1</List.Item>
23
+ <List.Item>List item 2</List.Item>
24
+ <List.Item>List item 3</List.Item>
25
+ </List>
26
+ <List isUnstyled>
27
+ <List.Item><Link href="https://www.canvaslms.com/try-canvas">Canvas by Instructure</Link></List.Item>
28
+ <List.Item><Link href="https://www.getbridge.com">Bridge by Instructure</Link></List.Item>
29
+ <List.Item><Link href="https://www.arcmedia.com">Arc by Instructure</Link></List.Item>
30
+ </List>
31
+ </div>
32
+ ```
33
+
34
+ ### Adding a delimiter
35
+
36
+ The `delimiter` lets you set a separator between items of the list. The predefined options are ['none', 'solid', and 'dashed'].
37
+
38
+ ```js
39
+ ---
40
+ type: example
41
+ ---
42
+ <div>
43
+ <List delimiter="none" margin="large 0">
44
+ <List.Item>{lorem.sentence()}</List.Item>
45
+ <List.Item>{lorem.sentence()}</List.Item>
46
+ <List.Item>{lorem.sentence()}</List.Item>
47
+ </List>
48
+ <List delimiter="solid" isUnstyled margin="large 0">
49
+ <List.Item>{lorem.sentence()}</List.Item>
50
+ <List.Item>{lorem.sentence()}</List.Item>
51
+ <List.Item>{lorem.sentence()}</List.Item>
52
+ </List>
53
+ <List delimiter="dashed" as="ol" margin="large 0">
54
+ <List.Item>{lorem.sentence()}</List.Item>
55
+ <List.Item>{lorem.sentence()}</List.Item>
56
+ <List.Item>{lorem.sentence()}</List.Item>
57
+ </List>
58
+ </div>
59
+ ```
60
+
61
+ ### Sizing
62
+
63
+ The `size` prop lets you adjust the font-size of the List. The predefined values are aligned with other components that use a 'size' prop for overall consistency within your application. The default is 'medium'.
64
+
65
+ ```javascript
66
+ ---
67
+ type: example
68
+ ---
69
+ <div>
70
+ <List size="small" margin="large 0">
71
+ <List.Item>{lorem.sentence()}</List.Item>
72
+ <List.Item>Small Size</List.Item>
73
+ <List.Item><b>Due:</b> Oct 1, 2019</List.Item>
74
+ </List>
75
+ <List margin="large 0">
76
+ <List.Item>{lorem.sentence()}</List.Item>
77
+ <List.Item>Medium (default) Size</List.Item>
78
+ <List.Item><b>Due:</b> Oct 1, 2019</List.Item>
79
+ </List>
80
+ <List size="large" margin="large 0">
81
+ <List.Item>{lorem.sentence()}</List.Item>
82
+ <List.Item>Large Size</List.Item>
83
+ <List.Item><b>Due:</b> Oct 1, 2019</List.Item>
84
+ </List>
85
+ </div>
86
+ ```
87
+
88
+ ### Adding predefined space between each List.Item
89
+
90
+ Use the `itemSpacing` prop to add space around your list’s items. To avoid unwanted excess space at the start/end of a List, the first and last List.Item will not receive margin via the `itemSpacing` prop.
91
+
92
+ > NOTE: itemSpacing has no affect on an List.Item that has the `delimiter` prop set to anything other than **none**.
93
+
94
+ ```js
95
+ ---
96
+ type: example
97
+ ---
98
+ <List isUnstyled itemSpacing="small">
99
+ <List.Item>{lorem.sentence()}</List.Item>
100
+ <List.Item><b>Due:</b> Oct 1, 2019</List.Item>
101
+ <List.Item><Link href="#">itemSpacing has been set to xx-small</Link></List.Item>
102
+ </List>
103
+ ```
104
+
105
+ **itemSpacing** set to `medium`
106
+
107
+ ```js
108
+ ---
109
+ type: example
110
+ ---
111
+ <List itemSpacing="medium">
112
+ <List.Item>{lorem.sentence()}</List.Item>
113
+ <List.Item><b>Due:</b> Oct 1, 2019</List.Item>
114
+ <List.Item><Link href="#">itemSpacing has been set to medium</Link></List.Item>
115
+ </List>
116
+ ```
117
+
118
+ **itemSpacing** set to `x-large`
119
+
120
+ ```js
121
+ ---
122
+ type: example
123
+ ---
124
+ <List isUnstyled itemSpacing="x-large">
125
+ <List.Item>{lorem.sentence()}</List.Item>
126
+ <List.Item><b>Due:</b> Oct 1, 2019</List.Item>
127
+ <List.Item><Link href="#">itemSpacing has been set to x-large</Link></List.Item>
128
+ </List>
129
+ ```
130
+
131
+ List.Items also accept the same `margin` prop as List, in the event you need different spacing around certain List.Items in the List.
132
+
133
+ ```js
134
+ ---
135
+ type: example
136
+ ---
137
+ <List isUnstyled itemSpacing="small">
138
+ <List.Item margin="x-large 0"><Link href="https://www.canvaslms.com/try-canvas">Canvas by Instructure</Link></List.Item>
139
+ <List.Item><Link href="https://www.getbridge.com">Bridge by Instructure</Link></List.Item>
140
+ <List.Item><Link href="https://www.arcmedia.com">Arc by Instructure</Link></List.Item>
141
+ </List>
142
+ ```