@instructure/ui-options 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 (149) hide show
  1. package/CHANGELOG.md +36 -294
  2. package/es/Options/{Item → v1/Item}/index.js +1 -1
  3. package/es/Options/{Separator → v1/Separator}/index.js +1 -1
  4. package/es/Options/{index.js → v1/index.js} +2 -2
  5. package/es/Options/v2/Item/index.js +127 -0
  6. package/es/Options/v2/Item/props.js +26 -0
  7. package/es/Options/v2/Item/styles.js +189 -0
  8. package/es/Options/v2/Item/theme.js +72 -0
  9. package/es/Options/v2/Separator/index.js +69 -0
  10. package/es/Options/v2/Separator/props.js +26 -0
  11. package/es/Options/v2/Separator/styles.js +46 -0
  12. package/es/Options/v2/Separator/theme.js +45 -0
  13. package/es/Options/v2/index.js +147 -0
  14. package/es/Options/v2/props.js +26 -0
  15. package/es/Options/v2/styles.js +57 -0
  16. package/es/Options/v2/theme.js +47 -0
  17. package/es/{index.js → exports/a.js} +6 -6
  18. package/es/exports/b.js +29 -0
  19. package/lib/Options/{Item → v1/Item}/index.js +1 -1
  20. package/lib/Options/{Separator → v1/Separator}/index.js +1 -1
  21. package/lib/Options/v1/index.js +153 -0
  22. package/lib/Options/v2/Item/index.js +132 -0
  23. package/lib/Options/v2/Item/props.js +31 -0
  24. package/lib/Options/v2/Item/styles.js +195 -0
  25. package/lib/Options/v2/Item/theme.js +78 -0
  26. package/lib/Options/v2/Separator/index.js +74 -0
  27. package/lib/Options/v2/Separator/props.js +31 -0
  28. package/lib/Options/v2/Separator/styles.js +52 -0
  29. package/lib/Options/v2/Separator/theme.js +51 -0
  30. package/lib/Options/{index.js → v2/index.js} +4 -5
  31. package/lib/Options/v2/props.js +31 -0
  32. package/lib/Options/v2/styles.js +63 -0
  33. package/lib/Options/v2/theme.js +53 -0
  34. package/lib/{index.js → exports/a.js} +7 -7
  35. package/lib/exports/b.js +47 -0
  36. package/package.json +40 -18
  37. package/src/Options/{Item → v1/Item}/index.tsx +1 -1
  38. package/src/Options/{Separator → v1/Separator}/index.tsx +1 -1
  39. package/src/Options/{index.tsx → v1/index.tsx} +2 -2
  40. package/src/Options/v2/Item/index.tsx +180 -0
  41. package/src/Options/v2/Item/props.ts +136 -0
  42. package/src/Options/v2/Item/styles.ts +205 -0
  43. package/src/Options/v2/Item/theme.ts +79 -0
  44. package/src/Options/v2/README.md +409 -0
  45. package/src/Options/v2/Separator/index.tsx +79 -0
  46. package/src/Options/v2/Separator/props.ts +52 -0
  47. package/src/Options/v2/Separator/styles.ts +52 -0
  48. package/src/Options/v2/Separator/theme.ts +48 -0
  49. package/src/Options/v2/index.tsx +188 -0
  50. package/src/Options/v2/props.ts +76 -0
  51. package/src/Options/v2/styles.ts +63 -0
  52. package/src/Options/v2/theme.ts +52 -0
  53. package/src/{index.ts → exports/a.ts} +9 -9
  54. package/src/exports/b.ts +38 -0
  55. package/tsconfig.build.tsbuildinfo +1 -1
  56. package/types/Options/v1/Item/index.d.ts.map +1 -0
  57. package/types/Options/v1/Item/props.d.ts.map +1 -0
  58. package/types/Options/v1/Item/styles.d.ts.map +1 -0
  59. package/types/Options/v1/Item/theme.d.ts.map +1 -0
  60. package/types/Options/v1/Separator/index.d.ts.map +1 -0
  61. package/types/Options/v1/Separator/props.d.ts.map +1 -0
  62. package/types/Options/v1/Separator/styles.d.ts.map +1 -0
  63. package/types/Options/v1/Separator/theme.d.ts.map +1 -0
  64. package/types/Options/v1/index.d.ts.map +1 -0
  65. package/types/Options/v1/props.d.ts.map +1 -0
  66. package/types/Options/v1/styles.d.ts.map +1 -0
  67. package/types/Options/v1/theme.d.ts.map +1 -0
  68. package/types/Options/v2/Item/index.d.ts +31 -0
  69. package/types/Options/v2/Item/index.d.ts.map +1 -0
  70. package/types/Options/v2/Item/props.d.ts +70 -0
  71. package/types/Options/v2/Item/props.d.ts.map +1 -0
  72. package/types/Options/v2/Item/styles.d.ts +15 -0
  73. package/types/Options/v2/Item/styles.d.ts.map +1 -0
  74. package/types/Options/v2/Item/theme.d.ts +11 -0
  75. package/types/Options/v2/Item/theme.d.ts.map +1 -0
  76. package/types/Options/v2/Separator/index.d.ts +22 -0
  77. package/types/Options/v2/Separator/index.d.ts.map +1 -0
  78. package/types/Options/v2/Separator/props.d.ts +17 -0
  79. package/types/Options/v2/Separator/props.d.ts.map +1 -0
  80. package/types/Options/v2/Separator/styles.d.ts +15 -0
  81. package/types/Options/v2/Separator/styles.d.ts.map +1 -0
  82. package/types/Options/v2/Separator/theme.d.ts +11 -0
  83. package/types/Options/v2/Separator/theme.d.ts.map +1 -0
  84. package/types/Options/v2/index.d.ts +43 -0
  85. package/types/Options/v2/index.d.ts.map +1 -0
  86. package/types/Options/v2/props.d.ts +32 -0
  87. package/types/Options/v2/props.d.ts.map +1 -0
  88. package/types/Options/v2/styles.d.ts +15 -0
  89. package/types/Options/v2/styles.d.ts.map +1 -0
  90. package/types/Options/v2/theme.d.ts +11 -0
  91. package/types/Options/v2/theme.d.ts.map +1 -0
  92. package/types/exports/a.d.ts +10 -0
  93. package/types/exports/a.d.ts.map +1 -0
  94. package/types/exports/b.d.ts +10 -0
  95. package/types/exports/b.d.ts.map +1 -0
  96. package/types/Options/Item/index.d.ts.map +0 -1
  97. package/types/Options/Item/props.d.ts.map +0 -1
  98. package/types/Options/Item/styles.d.ts.map +0 -1
  99. package/types/Options/Item/theme.d.ts.map +0 -1
  100. package/types/Options/Separator/index.d.ts.map +0 -1
  101. package/types/Options/Separator/props.d.ts.map +0 -1
  102. package/types/Options/Separator/styles.d.ts.map +0 -1
  103. package/types/Options/Separator/theme.d.ts.map +0 -1
  104. package/types/Options/index.d.ts.map +0 -1
  105. package/types/Options/props.d.ts.map +0 -1
  106. package/types/Options/styles.d.ts.map +0 -1
  107. package/types/Options/theme.d.ts.map +0 -1
  108. package/types/index.d.ts +0 -10
  109. package/types/index.d.ts.map +0 -1
  110. /package/es/Options/{Item → v1/Item}/props.js +0 -0
  111. /package/es/Options/{Item → v1/Item}/styles.js +0 -0
  112. /package/es/Options/{Item → v1/Item}/theme.js +0 -0
  113. /package/es/Options/{Separator → v1/Separator}/props.js +0 -0
  114. /package/es/Options/{Separator → v1/Separator}/styles.js +0 -0
  115. /package/es/Options/{Separator → v1/Separator}/theme.js +0 -0
  116. /package/es/Options/{props.js → v1/props.js} +0 -0
  117. /package/es/Options/{styles.js → v1/styles.js} +0 -0
  118. /package/es/Options/{theme.js → v1/theme.js} +0 -0
  119. /package/lib/Options/{Item → v1/Item}/props.js +0 -0
  120. /package/lib/Options/{Item → v1/Item}/styles.js +0 -0
  121. /package/lib/Options/{Item → v1/Item}/theme.js +0 -0
  122. /package/lib/Options/{Separator → v1/Separator}/props.js +0 -0
  123. /package/lib/Options/{Separator → v1/Separator}/styles.js +0 -0
  124. /package/lib/Options/{Separator → v1/Separator}/theme.js +0 -0
  125. /package/lib/Options/{props.js → v1/props.js} +0 -0
  126. /package/lib/Options/{styles.js → v1/styles.js} +0 -0
  127. /package/lib/Options/{theme.js → v1/theme.js} +0 -0
  128. /package/src/Options/{Item → v1/Item}/props.ts +0 -0
  129. /package/src/Options/{Item → v1/Item}/styles.ts +0 -0
  130. /package/src/Options/{Item → v1/Item}/theme.ts +0 -0
  131. /package/src/Options/{README.md → v1/README.md} +0 -0
  132. /package/src/Options/{Separator → v1/Separator}/props.ts +0 -0
  133. /package/src/Options/{Separator → v1/Separator}/styles.ts +0 -0
  134. /package/src/Options/{Separator → v1/Separator}/theme.ts +0 -0
  135. /package/src/Options/{props.ts → v1/props.ts} +0 -0
  136. /package/src/Options/{styles.ts → v1/styles.ts} +0 -0
  137. /package/src/Options/{theme.ts → v1/theme.ts} +0 -0
  138. /package/types/Options/{Item → v1/Item}/index.d.ts +0 -0
  139. /package/types/Options/{Item → v1/Item}/props.d.ts +0 -0
  140. /package/types/Options/{Item → v1/Item}/styles.d.ts +0 -0
  141. /package/types/Options/{Item → v1/Item}/theme.d.ts +0 -0
  142. /package/types/Options/{Separator → v1/Separator}/index.d.ts +0 -0
  143. /package/types/Options/{Separator → v1/Separator}/props.d.ts +0 -0
  144. /package/types/Options/{Separator → v1/Separator}/styles.d.ts +0 -0
  145. /package/types/Options/{Separator → v1/Separator}/theme.d.ts +0 -0
  146. /package/types/Options/{index.d.ts → v1/index.d.ts} +0 -0
  147. /package/types/Options/{props.d.ts → v1/props.d.ts} +0 -0
  148. /package/types/Options/{styles.d.ts → v1/styles.d.ts} +0 -0
  149. /package/types/Options/{theme.d.ts → v1/theme.d.ts} +0 -0
@@ -0,0 +1,79 @@
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 { getElementType, omitProps } from '@instructure/ui-react-utils'
28
+
29
+ import { withStyle } from '@instructure/emotion'
30
+
31
+ import generateStyles from './styles'
32
+ import type { OptionsSeparatorProps } from './props'
33
+ import { allowedProps } from './props'
34
+
35
+ /**
36
+ ---
37
+ parent: Options
38
+ id: Options.Separator
39
+ ---
40
+ @module Separator
41
+ **/
42
+ @withStyle(generateStyles)
43
+ class Separator extends Component<OptionsSeparatorProps> {
44
+ static readonly componentId = 'Options.Separator'
45
+
46
+ static allowedProps = allowedProps
47
+
48
+ static defaultProps = {
49
+ as: 'span'
50
+ } as const
51
+
52
+ componentDidMount() {
53
+ this.props.makeStyles?.()
54
+ }
55
+
56
+ componentDidUpdate() {
57
+ this.props.makeStyles?.()
58
+ }
59
+
60
+ render() {
61
+ const { as, styles, ...rest } = this.props
62
+
63
+ const ElementType = getElementType(Separator, this.props, () => as!)
64
+
65
+ return (
66
+ <ElementType role="none">
67
+ <div
68
+ // we need to omit the withStyle props
69
+ {...omitProps(rest, ['styles', 'makeStyles', 'themeOverride'])}
70
+ css={styles?.separator}
71
+ role="presentation"
72
+ />
73
+ </ElementType>
74
+ )
75
+ }
76
+ }
77
+
78
+ export default Separator
79
+ export { Separator }
@@ -0,0 +1,52 @@
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 type {
26
+ AsElementType,
27
+ OptionsSeparatorTheme,
28
+ OtherHTMLAttributes
29
+ } from '@instructure/shared-types'
30
+ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
31
+ import { AllHTMLAttributes } from 'react'
32
+
33
+ type OptionsSeparatorOwnProps = {
34
+ /**
35
+ * Element type to render as
36
+ */
37
+ as?: AsElementType
38
+ }
39
+
40
+ type PropKeys = keyof OptionsSeparatorOwnProps
41
+
42
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
43
+
44
+ type OptionsSeparatorProps = OptionsSeparatorOwnProps &
45
+ WithStyleProps<OptionsSeparatorTheme, OptionsSeparatorStyle> &
46
+ OtherHTMLAttributes<OptionsSeparatorOwnProps, AllHTMLAttributes<any>>
47
+
48
+ type OptionsSeparatorStyle = ComponentStyle<'separator'>
49
+ const allowedProps: AllowedPropKeys = ['as']
50
+
51
+ export type { OptionsSeparatorProps, OptionsSeparatorStyle }
52
+ export { allowedProps }
@@ -0,0 +1,52 @@
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 type { NewComponentTypes } from '@instructure/ui-themes'
26
+ import type { OptionsSeparatorStyle } from './props'
27
+
28
+ /**
29
+ * ---
30
+ * private: true
31
+ * ---
32
+ * Generates the style object from the theme and provided additional information
33
+ * @param {Object} componentTheme The theme variable object.
34
+ * @param {Object} props the props of the component, the style is applied to
35
+ * @param {Object} state the state 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['OptionsSeparator']
40
+ ): OptionsSeparatorStyle => {
41
+ return {
42
+ separator: {
43
+ label: 'separator',
44
+ height: componentTheme.height,
45
+ margin: `${componentTheme.marginVertical} ${componentTheme.marginHorizontal}`,
46
+ overflow: 'hidden',
47
+ background: componentTheme.background
48
+ }
49
+ }
50
+ }
51
+
52
+ export default generateStyle
@@ -0,0 +1,48 @@
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 type { Theme } from '@instructure/ui-themes'
26
+ import { OptionsSeparatorTheme } from '@instructure/shared-types'
27
+
28
+ /**
29
+ * Generates the theme object for the component from the theme and provided additional information
30
+ * @param {Object} theme The actual theme object.
31
+ * @return {Object} The final theme object with the overrides and component variables
32
+ */
33
+ const generateComponentTheme = (theme: Theme): OptionsSeparatorTheme => {
34
+ const { borders, colors, spacing } = theme
35
+
36
+ const componentVariables: OptionsSeparatorTheme = {
37
+ background: colors?.contrasts?.grey3045,
38
+ height: borders?.widthSmall,
39
+ margin: `0 ${spacing?.small}`
40
+ }
41
+
42
+ return {
43
+ ...componentVariables
44
+ }
45
+ }
46
+
47
+ export { generateComponentTheme as optionsSeparatorThemeGenerator }
48
+ export default generateComponentTheme
@@ -0,0 +1,188 @@
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 { ComponentElement, Component, Children } from 'react'
26
+
27
+ import {
28
+ omitProps,
29
+ matchComponentTypes,
30
+ callRenderProp,
31
+ safeCloneElement,
32
+ withDeterministicId
33
+ } from '@instructure/ui-react-utils'
34
+
35
+ import { View } from '@instructure/ui-view/latest'
36
+
37
+ import { withStyle } from '@instructure/emotion'
38
+
39
+ import generateStyles from './styles'
40
+
41
+ import { Item } from './Item'
42
+ import type { OptionsItemProps } from './Item/props'
43
+ import { Separator } from './Separator'
44
+ import type { OptionsSeparatorProps } from './Separator/props'
45
+
46
+ import type { OptionsProps } from './props'
47
+ import { allowedProps } from './props'
48
+ import { isAndroidOrIOS } from '@instructure/ui-utils'
49
+
50
+ type ItemChild = ComponentElement<OptionsItemProps, Item>
51
+ type SeparatorChild = ComponentElement<OptionsSeparatorProps, Separator>
52
+ type OptionsChild = ComponentElement<OptionsProps, Options>
53
+ type OptionsChildren = (ItemChild | SeparatorChild | OptionsChild)[]
54
+
55
+ /**
56
+ ---
57
+ category: components/utilities
58
+ ---
59
+ **/
60
+ @withDeterministicId()
61
+ @withStyle(generateStyles)
62
+ class Options extends Component<OptionsProps> {
63
+ static readonly componentId = 'Options'
64
+
65
+ static allowedProps = allowedProps
66
+
67
+ static defaultProps = {
68
+ as: 'span',
69
+ role: 'list',
70
+ elementRef: () => {},
71
+ renderLabel: null,
72
+ children: null
73
+ }
74
+
75
+ static Item = Item
76
+ static Separator = Separator
77
+
78
+ ref: Element | null = null
79
+
80
+ handleRef = (el: Element | null) => {
81
+ this.ref = el
82
+ }
83
+
84
+ componentDidMount() {
85
+ this.props.makeStyles?.()
86
+ }
87
+
88
+ componentDidUpdate() {
89
+ this.props.makeStyles?.()
90
+ }
91
+ _labelId = this.props.deterministicId!('Options-label')
92
+
93
+ get childAs() {
94
+ const { as } = this.props
95
+ if (as === 'ul' || as === 'ol') {
96
+ return 'li'
97
+ }
98
+ return undefined
99
+ }
100
+
101
+ renderLabel() {
102
+ const { renderLabel, styles } = this.props
103
+ return (
104
+ <span
105
+ id={this._labelId}
106
+ role="presentation"
107
+ // because TalkBack and iOS VoiceOver don't announce sub-menu labels, aria-hidden needs to be false to achive that
108
+ aria-hidden={isAndroidOrIOS() ? 'false' : 'true'}
109
+ css={styles?.label}
110
+ >
111
+ {callRenderProp(renderLabel)}
112
+ </span>
113
+ )
114
+ }
115
+
116
+ renderSubList(subOptions: OptionsChild) {
117
+ const { styles } = this.props
118
+ return (
119
+ <Item as={this.childAs} role="presentation" css={styles?.label}>
120
+ {subOptions}
121
+ </Item>
122
+ )
123
+ }
124
+
125
+ renderChildren() {
126
+ const { children } = this.props
127
+
128
+ return Children.map(children as OptionsChildren, (child) => {
129
+ if (matchComponentTypes<OptionsChild>(child, ['Options'])) {
130
+ return this.renderSubList(child)
131
+ }
132
+ if (matchComponentTypes(child, ['Item', 'Separator'])) {
133
+ return safeCloneElement(child, { as: this.childAs || child.props.as })
134
+ }
135
+
136
+ return undefined
137
+ })
138
+ }
139
+
140
+ get ariaLabelledby() {
141
+ if (this.props.renderLabel) {
142
+ return this._labelId
143
+ }
144
+
145
+ if (this.props['aria-labelledby']) {
146
+ return this.props['aria-labelledby']
147
+ }
148
+
149
+ return undefined
150
+ }
151
+
152
+ render() {
153
+ const passthroughProps = View.omitViewProps(
154
+ omitProps(this.props, Options.allowedProps),
155
+ Options
156
+ )
157
+
158
+ const { as, role, renderLabel, elementRef, styles } = this.props
159
+
160
+ return (
161
+ <div
162
+ css={styles?.options}
163
+ role="presentation"
164
+ ref={this.handleRef}
165
+ data-cid="Options"
166
+ >
167
+ {renderLabel && this.renderLabel()}
168
+ <View
169
+ {...passthroughProps}
170
+ elementRef={elementRef}
171
+ css={styles?.list}
172
+ as={as}
173
+ role={role}
174
+ display="block"
175
+ margin="none"
176
+ padding="none"
177
+ background="primary"
178
+ aria-labelledby={this.ariaLabelledby}
179
+ >
180
+ {this.renderChildren()}
181
+ </View>
182
+ </div>
183
+ )
184
+ }
185
+ }
186
+
187
+ export default Options
188
+ export { Options }
@@ -0,0 +1,76 @@
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 React from 'react'
25
+ import type {
26
+ AsElementType,
27
+ OptionsTheme,
28
+ OtherHTMLAttributes
29
+ } from '@instructure/shared-types'
30
+ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
31
+ import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
32
+ import { Renderable } from '@instructure/shared-types'
33
+
34
+ type OptionsOwnProps = {
35
+ /**
36
+ * Element type to render as
37
+ */
38
+ as?: AsElementType
39
+ /**
40
+ * The aria role of the element
41
+ */
42
+ role?: string
43
+ /**
44
+ * The the actual list element
45
+ */
46
+ elementRef?: (element: Element | null) => void
47
+ /**
48
+ * Content to render as a label. Mostly for when the component is nested
49
+ */
50
+ renderLabel?: Renderable
51
+
52
+ //TODO children has to be typed better
53
+ //e.g.: ChildrenPropTypes.oneOf(['Options', 'Item', 'Separator']))
54
+ children?: React.ReactNode
55
+ }
56
+
57
+ type PropKeys = keyof OptionsOwnProps
58
+
59
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
60
+
61
+ type OptionsProps = OptionsOwnProps &
62
+ WithStyleProps<OptionsTheme, OptionsStyle> &
63
+ OtherHTMLAttributes<OptionsOwnProps> &
64
+ WithDeterministicIdProps
65
+
66
+ type OptionsStyle = ComponentStyle<'options' | 'list' | 'label'>
67
+ const allowedProps: AllowedPropKeys = [
68
+ 'as',
69
+ 'role',
70
+ 'elementRef',
71
+ 'renderLabel',
72
+ 'children'
73
+ ]
74
+
75
+ export type { OptionsProps, OptionsStyle }
76
+ export { allowedProps }
@@ -0,0 +1,63 @@
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 type { NewComponentTypes } from '@instructure/ui-themes'
26
+ import type { OptionsStyle } from './props'
27
+
28
+ /**
29
+ * ---
30
+ * private: true
31
+ * ---
32
+ * Generates the style object from the theme and provided additional information
33
+ * @param {Object} componentTheme The theme variable object.
34
+ * @param {Object} props the props of the component, the style is applied to
35
+ * @param {Object} state the state 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['Options']
40
+ ): OptionsStyle => {
41
+ return {
42
+ options: {
43
+ label: 'options',
44
+ boxSizing: 'border-box',
45
+ wordWrap: 'break-word'
46
+ },
47
+ list: {
48
+ label: 'options__list',
49
+ listStyleType: 'none',
50
+ position: 'relative'
51
+ },
52
+ label: {
53
+ label: 'options__label',
54
+ color: componentTheme.labelColor,
55
+ cursor: 'default',
56
+ display: 'block',
57
+ fontWeight: componentTheme.labelFontWeight,
58
+ padding: `${componentTheme.nestedLabelPaddingVertical} ${componentTheme.nestedLabelPaddingHorizontal}`
59
+ }
60
+ }
61
+ }
62
+
63
+ export default generateStyle
@@ -0,0 +1,52 @@
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 type { Theme } from '@instructure/ui-themes'
26
+ import type { OptionsTheme } from '@instructure/shared-types'
27
+
28
+ /**
29
+ * Generates the theme object for the component from the theme and provided additional information
30
+ * @param {Object} theme The actual theme object.
31
+ * @return {Object} The final theme object with the overrides and component variables
32
+ */
33
+ const generateComponentTheme = (theme: Theme): OptionsTheme => {
34
+ const { colors, typography, spacing } = theme
35
+
36
+ const componentVariables: OptionsTheme = {
37
+ labelFontWeight: typography?.fontWeightBold,
38
+
39
+ background: colors?.contrasts?.white1010,
40
+ labelColor: colors?.contrasts?.grey125125,
41
+
42
+ labelPadding: `${spacing?.xSmall} 0`,
43
+ nestedLabelPadding: `${spacing?.xSmall} ${spacing?.small}`
44
+ }
45
+
46
+ return {
47
+ ...componentVariables
48
+ }
49
+ }
50
+
51
+ export { generateComponentTheme as optionsThemeGenerator }
52
+ export default generateComponentTheme
@@ -22,17 +22,17 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- export { Options } from './Options'
26
- export { Item as OptionItem } from './Options/Item'
27
- export { Separator as OptionSeparator } from './Options/Separator'
25
+ export { Options } from '../Options/v1'
26
+ export { Item as OptionItem } from '../Options/v1/Item'
27
+ export { Separator as OptionSeparator } from '../Options/v1/Separator'
28
28
 
29
- export { optionsThemeGenerator } from './Options/theme'
30
- export { optionsItemThemeGenerator } from './Options/Item/theme'
31
- export { optionsSeparatorThemeGenerator } from './Options/Separator/theme'
29
+ export { optionsThemeGenerator } from '../Options/v1/theme'
30
+ export { optionsItemThemeGenerator } from '../Options/v1/Item/theme'
31
+ export { optionsSeparatorThemeGenerator } from '../Options/v1/Separator/theme'
32
32
 
33
- export type { OptionsProps } from './Options/props'
33
+ export type { OptionsProps } from '../Options/v1/props'
34
34
  export type {
35
35
  OptionsItemProps,
36
36
  OptionsItemRenderProps
37
- } from './Options/Item/props'
38
- export type { OptionsSeparatorProps } from './Options/Separator/props'
37
+ } from '../Options/v1/Item/props'
38
+ export type { OptionsSeparatorProps } from '../Options/v1/Separator/props'
@@ -0,0 +1,38 @@
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
+ export { Options } from '../Options/v2'
26
+ export { Item as OptionItem } from '../Options/v2/Item'
27
+ export { Separator as OptionSeparator } from '../Options/v2/Separator'
28
+
29
+ export { optionsThemeGenerator } from '../Options/v2/theme'
30
+ export { optionsItemThemeGenerator } from '../Options/v2/Item/theme'
31
+ export { optionsSeparatorThemeGenerator } from '../Options/v2/Separator/theme'
32
+
33
+ export type { OptionsProps } from '../Options/v2/props'
34
+ export type {
35
+ OptionsItemProps,
36
+ OptionsItemRenderProps
37
+ } from '../Options/v2/Item/props'
38
+ export type { OptionsSeparatorProps } from '../Options/v2/Separator/props'