@instructure/ui-form-field 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 (248) hide show
  1. package/CHANGELOG.md +46 -300
  2. package/es/FormField/{index.js → v1/index.js} +1 -1
  3. package/es/FormField/v2/index.js +78 -0
  4. package/es/FormField/v2/props.js +26 -0
  5. package/es/FormFieldGroup/{index.js → v1/index.js} +5 -4
  6. package/es/FormFieldGroup/v2/index.js +130 -0
  7. package/es/FormFieldGroup/v2/props.js +26 -0
  8. package/es/FormFieldGroup/v2/styles.js +49 -0
  9. package/es/FormFieldLabel/{index.js → v1/index.js} +1 -1
  10. package/es/FormFieldLabel/v2/index.js +83 -0
  11. package/es/FormFieldLabel/v2/props.js +26 -0
  12. package/es/FormFieldLabel/v2/styles.js +62 -0
  13. package/es/FormFieldLabel/v2/theme.js +52 -0
  14. package/es/FormFieldLayout/{index.js → v1/index.js} +2 -2
  15. package/es/FormFieldLayout/{styles.js → v1/styles.js} +2 -2
  16. package/es/FormFieldLayout/v2/index.js +207 -0
  17. package/es/FormFieldLayout/v2/props.js +26 -0
  18. package/es/FormFieldLayout/v2/styles.js +171 -0
  19. package/es/FormFieldMessage/{index.js → v1/index.js} +1 -1
  20. package/es/FormFieldMessage/v2/index.js +96 -0
  21. package/es/FormFieldMessage/v2/props.js +26 -0
  22. package/es/FormFieldMessage/v2/styles.js +69 -0
  23. package/es/FormFieldMessages/{index.js → v1/index.js} +2 -2
  24. package/es/FormFieldMessages/v2/index.js +88 -0
  25. package/es/FormFieldMessages/v2/props.js +26 -0
  26. package/es/FormFieldMessages/v2/styles.js +50 -0
  27. package/es/{index.js → exports/a.js} +6 -6
  28. package/es/exports/b.js +29 -0
  29. package/lib/FormField/{index.js → v1/index.js} +3 -3
  30. package/lib/FormField/v2/index.js +85 -0
  31. package/lib/FormField/v2/props.js +31 -0
  32. package/lib/FormFieldGroup/{index.js → v1/index.js} +11 -10
  33. package/lib/FormFieldGroup/v2/index.js +136 -0
  34. package/lib/FormFieldGroup/v2/props.js +31 -0
  35. package/lib/FormFieldGroup/v2/styles.js +55 -0
  36. package/lib/FormFieldLabel/{index.js → v1/index.js} +1 -1
  37. package/lib/FormFieldLabel/v2/index.js +89 -0
  38. package/lib/FormFieldLabel/v2/props.js +31 -0
  39. package/lib/FormFieldLabel/v2/styles.js +68 -0
  40. package/lib/FormFieldLabel/v2/theme.js +58 -0
  41. package/lib/FormFieldLayout/{index.js → v1/index.js} +3 -3
  42. package/lib/FormFieldLayout/{styles.js → v1/styles.js} +1 -1
  43. package/lib/FormFieldLayout/v2/index.js +220 -0
  44. package/lib/FormFieldLayout/v2/props.js +31 -0
  45. package/lib/FormFieldLayout/v2/styles.js +177 -0
  46. package/lib/FormFieldMessage/{index.js → v1/index.js} +2 -2
  47. package/lib/FormFieldMessage/v2/index.js +101 -0
  48. package/lib/FormFieldMessage/v2/props.js +31 -0
  49. package/lib/FormFieldMessage/v2/styles.js +75 -0
  50. package/lib/FormFieldMessages/{index.js → v1/index.js} +3 -3
  51. package/lib/FormFieldMessages/v2/index.js +93 -0
  52. package/lib/FormFieldMessages/v2/props.js +31 -0
  53. package/lib/FormFieldMessages/v2/styles.js +56 -0
  54. package/lib/{index.js → exports/a.js} +12 -12
  55. package/lib/exports/b.js +47 -0
  56. package/package.json +43 -21
  57. package/src/FormField/{index.tsx → v1/index.tsx} +1 -1
  58. package/src/FormField/{props.ts → v1/props.ts} +1 -1
  59. package/src/FormField/v2/README.md +43 -0
  60. package/src/FormField/v2/index.tsx +87 -0
  61. package/src/FormField/v2/props.ts +104 -0
  62. package/src/FormFieldGroup/{index.tsx → v1/index.tsx} +6 -4
  63. package/src/FormFieldGroup/{props.ts → v1/props.ts} +2 -2
  64. package/src/FormFieldGroup/v2/README.md +114 -0
  65. package/src/FormFieldGroup/v2/index.tsx +182 -0
  66. package/src/FormFieldGroup/v2/props.ts +103 -0
  67. package/src/FormFieldGroup/v2/styles.ts +58 -0
  68. package/src/FormFieldLabel/{index.tsx → v1/index.tsx} +1 -1
  69. package/src/FormFieldLabel/v2/index.tsx +95 -0
  70. package/src/FormFieldLabel/v2/props.ts +49 -0
  71. package/src/FormFieldLabel/v2/styles.ts +74 -0
  72. package/src/FormFieldLabel/v2/theme.ts +56 -0
  73. package/src/FormFieldLayout/{index.tsx → v1/index.tsx} +2 -2
  74. package/src/FormFieldLayout/{props.ts → v1/props.ts} +1 -1
  75. package/src/FormFieldLayout/{styles.ts → v1/styles.ts} +2 -2
  76. package/src/FormFieldLayout/v2/index.tsx +237 -0
  77. package/src/FormFieldLayout/v2/props.ts +157 -0
  78. package/src/FormFieldLayout/v2/styles.ts +209 -0
  79. package/src/FormFieldMessage/{index.tsx → v1/index.tsx} +1 -1
  80. package/src/FormFieldMessage/{props.ts → v1/props.ts} +4 -1
  81. package/src/FormFieldMessage/{styles.ts → v1/styles.ts} +2 -3
  82. package/src/FormFieldMessage/v2/index.tsx +104 -0
  83. package/src/FormFieldMessage/v2/props.ts +48 -0
  84. package/src/FormFieldMessage/v2/styles.ts +76 -0
  85. package/src/FormFieldMessages/{index.tsx → v1/index.tsx} +2 -2
  86. package/src/FormFieldMessages/{props.ts → v1/props.ts} +1 -1
  87. package/src/FormFieldMessages/v2/index.tsx +99 -0
  88. package/src/FormFieldMessages/v2/props.ts +59 -0
  89. package/src/FormFieldMessages/v2/styles.ts +55 -0
  90. package/src/{index.ts → exports/a.ts} +17 -13
  91. package/src/exports/b.ts +43 -0
  92. package/tsconfig.build.json +1 -0
  93. package/tsconfig.build.tsbuildinfo +1 -1
  94. package/types/FormField/v1/index.d.ts.map +1 -0
  95. package/types/FormField/{props.d.ts → v1/props.d.ts} +1 -1
  96. package/types/FormField/v1/props.d.ts.map +1 -0
  97. package/types/FormField/v2/index.d.ts +23 -0
  98. package/types/FormField/v2/index.d.ts.map +1 -0
  99. package/types/FormField/v2/props.d.ts +57 -0
  100. package/types/FormField/v2/props.d.ts.map +1 -0
  101. package/types/FormFieldGroup/{index.d.ts → v1/index.d.ts} +1 -1
  102. package/types/FormFieldGroup/v1/index.d.ts.map +1 -0
  103. package/types/FormFieldGroup/{props.d.ts → v1/props.d.ts} +2 -2
  104. package/types/FormFieldGroup/v1/props.d.ts.map +1 -0
  105. package/types/FormFieldGroup/v1/styles.d.ts.map +1 -0
  106. package/types/FormFieldGroup/v1/theme.d.ts.map +1 -0
  107. package/types/FormFieldGroup/v2/index.d.ts +45 -0
  108. package/types/FormFieldGroup/v2/index.d.ts.map +1 -0
  109. package/types/FormFieldGroup/v2/props.d.ts +48 -0
  110. package/types/FormFieldGroup/v2/props.d.ts.map +1 -0
  111. package/types/FormFieldGroup/v2/styles.d.ts +14 -0
  112. package/types/FormFieldGroup/v2/styles.d.ts.map +1 -0
  113. package/types/FormFieldLabel/v1/index.d.ts.map +1 -0
  114. package/types/FormFieldLabel/v1/props.d.ts.map +1 -0
  115. package/types/FormFieldLabel/v1/styles.d.ts.map +1 -0
  116. package/types/FormFieldLabel/v1/theme.d.ts.map +1 -0
  117. package/types/FormFieldLabel/v2/index.d.ts +38 -0
  118. package/types/FormFieldLabel/v2/index.d.ts.map +1 -0
  119. package/types/FormFieldLabel/v2/props.d.ts +14 -0
  120. package/types/FormFieldLabel/v2/props.d.ts.map +1 -0
  121. package/types/FormFieldLabel/v2/styles.d.ts +15 -0
  122. package/types/FormFieldLabel/v2/styles.d.ts.map +1 -0
  123. package/types/FormFieldLabel/v2/theme.d.ts +10 -0
  124. package/types/FormFieldLabel/v2/theme.d.ts.map +1 -0
  125. package/types/FormFieldLayout/v1/index.d.ts.map +1 -0
  126. package/types/FormFieldLayout/{props.d.ts → v1/props.d.ts} +1 -1
  127. package/types/FormFieldLayout/v1/props.d.ts.map +1 -0
  128. package/types/FormFieldLayout/v1/styles.d.ts.map +1 -0
  129. package/types/FormFieldLayout/v1/theme.d.ts.map +1 -0
  130. package/types/FormFieldLayout/v2/index.d.ts +14 -0
  131. package/types/FormFieldLayout/v2/index.d.ts.map +1 -0
  132. package/types/FormFieldLayout/v2/props.d.ts +90 -0
  133. package/types/FormFieldLayout/v2/props.d.ts.map +1 -0
  134. package/types/FormFieldLayout/v2/styles.d.ts +25 -0
  135. package/types/FormFieldLayout/v2/styles.d.ts.map +1 -0
  136. package/types/FormFieldMessage/{index.d.ts → v1/index.d.ts} +2 -2
  137. package/types/FormFieldMessage/v1/index.d.ts.map +1 -0
  138. package/types/FormFieldMessage/{props.d.ts → v1/props.d.ts} +1 -1
  139. package/types/FormFieldMessage/v1/props.d.ts.map +1 -0
  140. package/types/FormFieldMessage/v1/styles.d.ts.map +1 -0
  141. package/types/FormFieldMessage/v1/theme.d.ts.map +1 -0
  142. package/types/FormFieldMessage/v2/index.d.ts +24 -0
  143. package/types/FormFieldMessage/v2/index.d.ts.map +1 -0
  144. package/types/FormFieldMessage/v2/props.d.ts +16 -0
  145. package/types/FormFieldMessage/v2/props.d.ts.map +1 -0
  146. package/types/FormFieldMessage/v2/styles.d.ts +18 -0
  147. package/types/FormFieldMessage/v2/styles.d.ts.map +1 -0
  148. package/types/FormFieldMessages/{index.d.ts → v1/index.d.ts} +1 -1
  149. package/types/FormFieldMessages/v1/index.d.ts.map +1 -0
  150. package/types/FormFieldMessages/{props.d.ts → v1/props.d.ts} +1 -1
  151. package/types/FormFieldMessages/v1/props.d.ts.map +1 -0
  152. package/types/FormFieldMessages/v1/styles.d.ts.map +1 -0
  153. package/types/FormFieldMessages/v1/theme.d.ts.map +1 -0
  154. package/types/FormFieldMessages/v2/index.d.ts +36 -0
  155. package/types/FormFieldMessages/v2/index.d.ts.map +1 -0
  156. package/types/FormFieldMessages/v2/props.d.ts +25 -0
  157. package/types/FormFieldMessages/v2/props.d.ts.map +1 -0
  158. package/types/FormFieldMessages/v2/styles.d.ts +14 -0
  159. package/types/FormFieldMessages/v2/styles.d.ts.map +1 -0
  160. package/types/exports/a.d.ts +14 -0
  161. package/types/exports/a.d.ts.map +1 -0
  162. package/types/exports/b.d.ts +14 -0
  163. package/types/exports/b.d.ts.map +1 -0
  164. package/types/utils/v1/FormPropTypes.d.ts.map +1 -0
  165. package/types/FormField/index.d.ts.map +0 -1
  166. package/types/FormField/props.d.ts.map +0 -1
  167. package/types/FormFieldGroup/index.d.ts.map +0 -1
  168. package/types/FormFieldGroup/props.d.ts.map +0 -1
  169. package/types/FormFieldGroup/styles.d.ts.map +0 -1
  170. package/types/FormFieldGroup/theme.d.ts.map +0 -1
  171. package/types/FormFieldLabel/index.d.ts.map +0 -1
  172. package/types/FormFieldLabel/props.d.ts.map +0 -1
  173. package/types/FormFieldLabel/styles.d.ts.map +0 -1
  174. package/types/FormFieldLabel/theme.d.ts.map +0 -1
  175. package/types/FormFieldLayout/index.d.ts.map +0 -1
  176. package/types/FormFieldLayout/props.d.ts.map +0 -1
  177. package/types/FormFieldLayout/styles.d.ts.map +0 -1
  178. package/types/FormFieldLayout/theme.d.ts.map +0 -1
  179. package/types/FormFieldMessage/index.d.ts.map +0 -1
  180. package/types/FormFieldMessage/props.d.ts.map +0 -1
  181. package/types/FormFieldMessage/styles.d.ts.map +0 -1
  182. package/types/FormFieldMessage/theme.d.ts.map +0 -1
  183. package/types/FormFieldMessages/index.d.ts.map +0 -1
  184. package/types/FormFieldMessages/props.d.ts.map +0 -1
  185. package/types/FormFieldMessages/styles.d.ts.map +0 -1
  186. package/types/FormFieldMessages/theme.d.ts.map +0 -1
  187. package/types/FormPropTypes.d.ts.map +0 -1
  188. package/types/index.d.ts +0 -14
  189. package/types/index.d.ts.map +0 -1
  190. /package/es/FormField/{props.js → v1/props.js} +0 -0
  191. /package/es/FormFieldGroup/{props.js → v1/props.js} +0 -0
  192. /package/es/FormFieldGroup/{styles.js → v1/styles.js} +0 -0
  193. /package/es/FormFieldGroup/{theme.js → v1/theme.js} +0 -0
  194. /package/es/FormFieldLabel/{props.js → v1/props.js} +0 -0
  195. /package/es/FormFieldLabel/{styles.js → v1/styles.js} +0 -0
  196. /package/es/FormFieldLabel/{theme.js → v1/theme.js} +0 -0
  197. /package/es/FormFieldLayout/{props.js → v1/props.js} +0 -0
  198. /package/es/FormFieldLayout/{theme.js → v1/theme.js} +0 -0
  199. /package/es/FormFieldMessage/{props.js → v1/props.js} +0 -0
  200. /package/es/FormFieldMessage/{styles.js → v1/styles.js} +0 -0
  201. /package/es/FormFieldMessage/{theme.js → v1/theme.js} +0 -0
  202. /package/es/FormFieldMessages/{props.js → v1/props.js} +0 -0
  203. /package/es/FormFieldMessages/{styles.js → v1/styles.js} +0 -0
  204. /package/es/FormFieldMessages/{theme.js → v1/theme.js} +0 -0
  205. /package/es/{FormPropTypes.js → utils/v1/FormPropTypes.js} +0 -0
  206. /package/lib/FormField/{props.js → v1/props.js} +0 -0
  207. /package/lib/FormFieldGroup/{props.js → v1/props.js} +0 -0
  208. /package/lib/FormFieldGroup/{styles.js → v1/styles.js} +0 -0
  209. /package/lib/FormFieldGroup/{theme.js → v1/theme.js} +0 -0
  210. /package/lib/FormFieldLabel/{props.js → v1/props.js} +0 -0
  211. /package/lib/FormFieldLabel/{styles.js → v1/styles.js} +0 -0
  212. /package/lib/FormFieldLabel/{theme.js → v1/theme.js} +0 -0
  213. /package/lib/FormFieldLayout/{props.js → v1/props.js} +0 -0
  214. /package/lib/FormFieldLayout/{theme.js → v1/theme.js} +0 -0
  215. /package/lib/FormFieldMessage/{props.js → v1/props.js} +0 -0
  216. /package/lib/FormFieldMessage/{styles.js → v1/styles.js} +0 -0
  217. /package/lib/FormFieldMessage/{theme.js → v1/theme.js} +0 -0
  218. /package/lib/FormFieldMessages/{props.js → v1/props.js} +0 -0
  219. /package/lib/FormFieldMessages/{styles.js → v1/styles.js} +0 -0
  220. /package/lib/FormFieldMessages/{theme.js → v1/theme.js} +0 -0
  221. /package/lib/{FormPropTypes.js → utils/v1/FormPropTypes.js} +0 -0
  222. /package/src/FormField/{README.md → v1/README.md} +0 -0
  223. /package/src/FormFieldGroup/{README.md → v1/README.md} +0 -0
  224. /package/src/FormFieldGroup/{styles.ts → v1/styles.ts} +0 -0
  225. /package/src/FormFieldGroup/{theme.ts → v1/theme.ts} +0 -0
  226. /package/src/FormFieldLabel/{props.ts → v1/props.ts} +0 -0
  227. /package/src/FormFieldLabel/{styles.ts → v1/styles.ts} +0 -0
  228. /package/src/FormFieldLabel/{theme.ts → v1/theme.ts} +0 -0
  229. /package/src/FormFieldLayout/{theme.ts → v1/theme.ts} +0 -0
  230. /package/src/FormFieldMessage/{theme.ts → v1/theme.ts} +0 -0
  231. /package/src/FormFieldMessages/{styles.ts → v1/styles.ts} +0 -0
  232. /package/src/FormFieldMessages/{theme.ts → v1/theme.ts} +0 -0
  233. /package/src/{FormPropTypes.ts → utils/v1/FormPropTypes.ts} +0 -0
  234. /package/types/FormField/{index.d.ts → v1/index.d.ts} +0 -0
  235. /package/types/FormFieldGroup/{styles.d.ts → v1/styles.d.ts} +0 -0
  236. /package/types/FormFieldGroup/{theme.d.ts → v1/theme.d.ts} +0 -0
  237. /package/types/FormFieldLabel/{index.d.ts → v1/index.d.ts} +0 -0
  238. /package/types/FormFieldLabel/{props.d.ts → v1/props.d.ts} +0 -0
  239. /package/types/FormFieldLabel/{styles.d.ts → v1/styles.d.ts} +0 -0
  240. /package/types/FormFieldLabel/{theme.d.ts → v1/theme.d.ts} +0 -0
  241. /package/types/FormFieldLayout/{index.d.ts → v1/index.d.ts} +0 -0
  242. /package/types/FormFieldLayout/{styles.d.ts → v1/styles.d.ts} +0 -0
  243. /package/types/FormFieldLayout/{theme.d.ts → v1/theme.d.ts} +0 -0
  244. /package/types/FormFieldMessage/{styles.d.ts → v1/styles.d.ts} +0 -0
  245. /package/types/FormFieldMessage/{theme.d.ts → v1/theme.d.ts} +0 -0
  246. /package/types/FormFieldMessages/{styles.d.ts → v1/styles.d.ts} +0 -0
  247. /package/types/FormFieldMessages/{theme.d.ts → v1/theme.d.ts} +0 -0
  248. /package/types/{FormPropTypes.d.ts → utils/v1/FormPropTypes.d.ts} +0 -0
@@ -0,0 +1,182 @@
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, Children, ReactElement, AriaAttributes } from 'react'
26
+
27
+ import { Grid } from '@instructure/ui-grid/latest'
28
+ import { pickProps, omitProps } from '@instructure/ui-react-utils'
29
+ import { withStyle } from '@instructure/emotion'
30
+
31
+ import { allowedProps as formFieldLayoutAllowedProps } from '../../FormFieldLayout/v2/props'
32
+
33
+ import { FormFieldLayout } from '../../FormFieldLayout/v2'
34
+
35
+ import generateStyle from './styles'
36
+
37
+ import { allowedProps } from './props'
38
+ import type { FormFieldGroupProps } from './props'
39
+
40
+ /**
41
+ ---
42
+ category: components
43
+ ---
44
+ **/
45
+ @withStyle(generateStyle)
46
+ class FormFieldGroup extends Component<FormFieldGroupProps> {
47
+ static readonly componentId = 'FormFieldGroup'
48
+
49
+ static allowedProps = allowedProps
50
+ static defaultProps = {
51
+ as: 'fieldset',
52
+ disabled: false,
53
+ rowSpacing: 'medium',
54
+ colSpacing: 'small',
55
+ vAlign: 'middle',
56
+ isGroup: true
57
+ }
58
+
59
+ ref: Element | null = null
60
+
61
+ handleRef = (el: Element | null) => {
62
+ const { elementRef } = this.props
63
+
64
+ this.ref = el
65
+
66
+ if (typeof elementRef === 'function') {
67
+ elementRef(el)
68
+ }
69
+ }
70
+
71
+ componentDidMount() {
72
+ this.props.makeStyles?.()
73
+ }
74
+
75
+ componentDidUpdate() {
76
+ this.props.makeStyles?.()
77
+ }
78
+
79
+ get invalid() {
80
+ return (
81
+ !!this.props.messages &&
82
+ this.props.messages.findIndex((message) => {
83
+ return message.type === 'error' || message.type === 'newError'
84
+ }) >= 0
85
+ )
86
+ }
87
+
88
+ renderColumns() {
89
+ return Children.map(this.props.children, (child, index) => {
90
+ return child ? (
91
+ <Grid.Col
92
+ width={
93
+ (child as ReactElement).props &&
94
+ (child as ReactElement<any>).props.width
95
+ ? 'auto'
96
+ : undefined
97
+ }
98
+ key={index}
99
+ >
100
+ {child}
101
+ </Grid.Col>
102
+ ) : null
103
+ })
104
+ }
105
+
106
+ renderChildren() {
107
+ return (
108
+ <Grid
109
+ colSpacing={this.props.colSpacing}
110
+ rowSpacing={this.props.rowSpacing}
111
+ vAlign={this.props.vAlign}
112
+ startAt={
113
+ this.props.startAt ||
114
+ (this.props.layout === 'columns' ? 'medium' : null)
115
+ }
116
+ >
117
+ <Grid.Row>{this.renderColumns()}</Grid.Row>
118
+ </Grid>
119
+ )
120
+ }
121
+
122
+ renderFields() {
123
+ const { styles } = this.props
124
+
125
+ return (
126
+ <span key="fields" css={styles?.formFieldGroup}>
127
+ {this.renderChildren()}
128
+ </span>
129
+ )
130
+ }
131
+
132
+ render() {
133
+ const { styles, makeStyles, isGroup, ...props } = this.props
134
+ // This is quite ugly, but according to ARIA spec the `aria-invalid` prop
135
+ // can only be used with certain roles see
136
+ // https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-invalid#associated_roles
137
+ // `aria-invalid` is put on in FormFieldLayout because the error message
138
+ // DOM part gets there its ID.
139
+ let ariaInvalid: AriaAttributes['aria-invalid'] = undefined
140
+ if (
141
+ this.props.role &&
142
+ this.invalid &&
143
+ [
144
+ 'application',
145
+ 'checkbox',
146
+ 'combobox',
147
+ 'gridcell',
148
+ 'listbox',
149
+ 'radiogroup',
150
+ 'slider',
151
+ 'spinbutton',
152
+ 'textbox',
153
+ 'tree',
154
+ 'columnheader',
155
+ 'rowheader',
156
+ 'searchbox',
157
+ 'switch',
158
+ 'treegrid'
159
+ ].includes(this.props.role)
160
+ ) {
161
+ ariaInvalid = 'true'
162
+ }
163
+ return (
164
+ <FormFieldLayout
165
+ {...omitProps(props, FormFieldGroup.allowedProps)}
166
+ {...pickProps(props, formFieldLayoutAllowedProps)}
167
+ vAlign={props.vAlign}
168
+ layout={props.layout === 'inline' ? 'inline' : 'stacked'}
169
+ label={props.description}
170
+ aria-disabled={props.disabled ? 'true' : undefined}
171
+ aria-invalid={ariaInvalid}
172
+ elementRef={this.handleRef}
173
+ isGroup={isGroup}
174
+ >
175
+ {this.renderFields()}
176
+ </FormFieldLayout>
177
+ )
178
+ }
179
+ }
180
+
181
+ export default FormFieldGroup
182
+ export { FormFieldGroup }
@@ -0,0 +1,103 @@
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
+ FormFieldGroupTheme,
28
+ OtherHTMLAttributes
29
+ } from '@instructure/shared-types'
30
+ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
31
+ import type { FormFieldLayoutOwnProps } from '../../FormFieldLayout/v2/props'
32
+ import type { FormMessage } from '../../utils/v1/FormPropTypes'
33
+
34
+ type FormFieldGroupOwnProps = {
35
+ description: React.ReactNode
36
+ /**
37
+ * the element type to render as
38
+ */
39
+ as?: AsElementType
40
+ /**
41
+ * Array of objects with shape: `{
42
+ * text: React.ReactNode,
43
+ * type: One of: ['newError', 'error', 'hint', 'success', 'screenreader-only']
44
+ * }`
45
+ */
46
+ messages?: FormMessage[]
47
+ /**
48
+ * id for the form field messages
49
+ */
50
+ messagesId?: string
51
+ /**
52
+ * Whether the field group is disabled. When true, error and success messages will be hidden.
53
+ */
54
+ disabled?: boolean
55
+ /**
56
+ * Whether the field group is read-only. When true, error and success messages will be hidden.
57
+ */
58
+ readOnly?: boolean
59
+ children?: React.ReactNode
60
+ layout?: 'stacked' | 'columns' | 'inline'
61
+ rowSpacing?: 'none' | 'small' | 'medium' | 'large'
62
+ colSpacing?: 'none' | 'small' | 'medium' | 'large'
63
+ vAlign?: 'top' | 'middle' | 'bottom'
64
+ startAt?: 'small' | 'medium' | 'large' | 'x-large' | null
65
+ /**
66
+ * provides a reference to the underlying html root element
67
+ */
68
+ elementRef?: (element: Element | null) => void
69
+ }
70
+
71
+ type PropKeys = keyof FormFieldGroupOwnProps
72
+
73
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
74
+
75
+ type FormFieldGroupProps = FormFieldGroupOwnProps &
76
+ WithStyleProps<FormFieldGroupTheme, FormFieldGroupStyle> &
77
+ OtherHTMLAttributes<FormFieldGroupOwnProps> &
78
+ // Adding other props that can be passed to FormFieldLayout,
79
+ // excluding the ones we set manually
80
+ Omit<
81
+ FormFieldLayoutOwnProps,
82
+ 'messages' | 'messagesId' | 'vAlign' | 'layout' | 'label' | 'children'
83
+ >
84
+
85
+ type FormFieldGroupStyle = ComponentStyle<'formFieldGroup'>
86
+ const allowedProps: AllowedPropKeys = [
87
+ 'description',
88
+ 'as',
89
+ 'messages',
90
+ 'messagesId',
91
+ 'disabled',
92
+ 'readOnly',
93
+ 'children',
94
+ 'layout',
95
+ 'rowSpacing',
96
+ 'colSpacing',
97
+ 'vAlign',
98
+ 'startAt',
99
+ 'elementRef'
100
+ ]
101
+
102
+ export type { FormFieldGroupProps, FormFieldGroupStyle }
103
+ export { allowedProps }
@@ -0,0 +1,58 @@
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 { FormFieldGroupProps, FormFieldGroupStyle } from './props'
26
+
27
+ /**
28
+ * ---
29
+ * private: true
30
+ * ---
31
+ * Generates the style object from the theme and provided additional information
32
+ * @param {Object} componentTheme The theme variable object.
33
+ * @param {Object} props the props of the component, the style is applied to
34
+ * @param {Object} state the state of the component, the style is applied to
35
+ * @return {Object} The final style object, which will be used in the component
36
+ */
37
+ const generateStyle = (
38
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
39
+ _componentTheme: {},
40
+ props: FormFieldGroupProps
41
+ ): FormFieldGroupStyle => {
42
+ const { disabled } = props
43
+
44
+ return {
45
+ formFieldGroup: {
46
+ label: 'formFieldGroup',
47
+ display: 'block',
48
+
49
+ ...(disabled && {
50
+ opacity: 0.6,
51
+ cursor: 'not-allowed',
52
+ pointerEvents: 'none'
53
+ })
54
+ }
55
+ }
56
+ }
57
+
58
+ export default generateStyle
@@ -25,7 +25,7 @@
25
25
  import { Component } from 'react'
26
26
 
27
27
  import { omitProps, getElementType } from '@instructure/ui-react-utils'
28
- import { withStyle } from '@instructure/emotion'
28
+ import { withStyleLegacy as withStyle } from '@instructure/emotion'
29
29
 
30
30
  import generateStyle from './styles'
31
31
  import generateComponentTheme from './theme'
@@ -0,0 +1,95 @@
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 { omitProps, getElementType } from '@instructure/ui-react-utils'
28
+ import { withStyleLegacy as withStyle } from '@instructure/emotion'
29
+
30
+ import generateStyle from './styles'
31
+ import generateComponentTheme from './theme'
32
+
33
+ import { allowedProps } from './props'
34
+ import type { FormFieldLabelProps } from './props'
35
+
36
+ /**
37
+ ---
38
+ parent: FormField
39
+ ---
40
+
41
+ This is a helper component that is used by most of the custom form
42
+ components. In most cases it shouldn't be used directly.
43
+
44
+ ```js
45
+ ---
46
+ type: example
47
+ ---
48
+ <FormFieldLabel>Hello</FormFieldLabel>
49
+ ```
50
+
51
+ @deprecated since version 10. This is an internal component that will be
52
+ removed in the future
53
+ **/
54
+ @withStyle(generateStyle, generateComponentTheme)
55
+ class FormFieldLabel extends Component<FormFieldLabelProps> {
56
+ static readonly componentId = 'FormFieldLabel'
57
+
58
+ static allowedProps = allowedProps
59
+ static defaultProps = {
60
+ as: 'span'
61
+ } as const
62
+
63
+ ref: Element | null = null
64
+
65
+ handleRef = (el: Element | null) => {
66
+ this.ref = el
67
+ }
68
+
69
+ componentDidMount() {
70
+ this.props.makeStyles?.()
71
+ }
72
+
73
+ componentDidUpdate() {
74
+ this.props.makeStyles?.()
75
+ }
76
+
77
+ render() {
78
+ const ElementType = getElementType(FormFieldLabel, this.props)
79
+
80
+ const { styles, children } = this.props
81
+
82
+ return (
83
+ <ElementType
84
+ {...omitProps(this.props, FormFieldLabel.allowedProps)}
85
+ css={styles?.formFieldLabel}
86
+ ref={this.handleRef}
87
+ >
88
+ {children}
89
+ </ElementType>
90
+ )
91
+ }
92
+ }
93
+
94
+ export default FormFieldLabel
95
+ export { FormFieldLabel }
@@ -0,0 +1,49 @@
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
+ FormFieldLabelTheme,
28
+ OtherHTMLAttributes
29
+ } from '@instructure/shared-types'
30
+ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
31
+
32
+ type FormFieldLabelOwnProps = {
33
+ children: React.ReactNode
34
+ as?: AsElementType
35
+ }
36
+
37
+ type PropKeys = keyof FormFieldLabelOwnProps
38
+
39
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
40
+
41
+ type FormFieldLabelProps = FormFieldLabelOwnProps &
42
+ WithStyleProps<FormFieldLabelTheme, FormFieldLabelStyle> &
43
+ OtherHTMLAttributes<FormFieldLabelOwnProps>
44
+
45
+ type FormFieldLabelStyle = ComponentStyle<'formFieldLabel'>
46
+ const allowedProps: AllowedPropKeys = ['as', 'children']
47
+
48
+ export type { FormFieldLabelProps, FormFieldLabelStyle }
49
+ export { allowedProps }
@@ -0,0 +1,74 @@
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 { hasVisibleChildren } from '@instructure/ui-a11y-utils'
26
+
27
+ import type { FormFieldLabelTheme } from '@instructure/shared-types'
28
+ import type { FormFieldLabelProps, FormFieldLabelStyle } from './props'
29
+
30
+ /**
31
+ * ---
32
+ * private: true
33
+ * ---
34
+ * Generates the style object from the theme and provided additional information
35
+ * @param {Object} componentTheme The theme variable object.
36
+ * @param {Object} props the props of the component, the style is applied to
37
+ * @param {Object} state the state of the component, the style is applied to
38
+ * @return {Object} The final style object, which will be used in the component
39
+ */
40
+ const generateStyle = (
41
+ componentTheme: FormFieldLabelTheme,
42
+ props: FormFieldLabelProps
43
+ ): FormFieldLabelStyle => {
44
+ const { children } = props
45
+
46
+ const hasContent = hasVisibleChildren(children)
47
+
48
+ const labelStyles = {
49
+ all: 'initial',
50
+ display: 'block',
51
+ ...(hasContent && {
52
+ color: componentTheme.color,
53
+ fontFamily: componentTheme.fontFamily,
54
+ fontWeight: componentTheme.fontWeight,
55
+ fontSize: componentTheme.fontSize,
56
+ lineHeight: componentTheme.lineHeight,
57
+ margin: 0,
58
+ textAlign: 'inherit'
59
+ })
60
+ }
61
+
62
+ return {
63
+ formFieldLabel: {
64
+ label: 'formFieldLabel',
65
+ ...labelStyles,
66
+
67
+ // NOTE: needs separate groups for `:is()` and `:-webkit-any()` because of css selector group validation (see https://www.w3.org/TR/selectors-3/#grouping)
68
+ '&:is(label)': labelStyles,
69
+ '&:-webkit-any(label)': labelStyles
70
+ }
71
+ }
72
+ }
73
+
74
+ export default generateStyle
@@ -0,0 +1,56 @@
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, ThemeSpecificStyle } from '@instructure/ui-themes'
26
+ import { FormFieldLabelTheme } 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): FormFieldLabelTheme => {
34
+ const { colors, typography, key: themeName } = theme
35
+
36
+ const themeSpecificStyle: ThemeSpecificStyle<FormFieldLabelTheme> = {
37
+ canvas: {
38
+ color: theme['ic-brand-font-color-dark']
39
+ }
40
+ }
41
+
42
+ const componentVariables: FormFieldLabelTheme = {
43
+ color: colors?.contrasts?.grey125125,
44
+ fontFamily: typography?.fontFamily,
45
+ fontWeight: typography?.fontWeightBold,
46
+ fontSize: typography?.fontSizeMedium,
47
+ lineHeight: typography?.lineHeightFit
48
+ }
49
+
50
+ return {
51
+ ...componentVariables,
52
+ ...themeSpecificStyle[themeName]
53
+ }
54
+ }
55
+
56
+ export default generateComponentTheme
@@ -30,8 +30,8 @@ import {
30
30
  withDeterministicId
31
31
  } from '@instructure/ui-react-utils'
32
32
 
33
- import { withStyle } from '@instructure/emotion'
34
- import { FormFieldMessages } from '../FormFieldMessages'
33
+ import { withStyleLegacy as withStyle } from '@instructure/emotion'
34
+ import { FormFieldMessages } from '../../FormFieldMessages/v1'
35
35
  import generateStyle from './styles'
36
36
  import { allowedProps, FormFieldStyleProps } from './props'
37
37
  import type { FormFieldLayoutProps } from './props'
@@ -31,7 +31,7 @@ import type {
31
31
  ComponentStyle,
32
32
  Spacing
33
33
  } from '@instructure/emotion'
34
- import type { FormMessage } from '../FormPropTypes'
34
+ import type { FormMessage } from '../../utils/v1/FormPropTypes'
35
35
  import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
36
36
 
37
37
  type FormFieldLayoutOwnProps = {
@@ -28,7 +28,7 @@ import type {
28
28
  FormFieldStyleProps
29
29
  } from './props'
30
30
  import type { FormFieldLayoutTheme } from '@instructure/shared-types'
31
- import { mapSpacingToShorthand } from '@instructure/emotion'
31
+ import { calcSpacingFromShorthand } from '@instructure/emotion'
32
32
 
33
33
  const generateGridLayout = (
34
34
  isInlineLayout: boolean,
@@ -77,7 +77,7 @@ const generateStyle = (
77
77
  ): FormFieldLayoutStyle => {
78
78
  const { inline, layout, vAlign, labelAlign, margin, messages } = props
79
79
  const { hasMessages, hasVisibleLabel, hasNewErrorMsgAndIsGroup } = styleProps
80
- const cssMargin = mapSpacingToShorthand(margin, componentTheme.spacing)
80
+ const cssMargin = calcSpacingFromShorthand(margin, componentTheme.spacing)
81
81
  const isInlineLayout = layout === 'inline'
82
82
 
83
83
  const hasNonEmptyMessages = messages?.reduce(