@instructure/ui-form-field 10.12.0 → 10.12.1-snapshot-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/es/FormField/index.js +0 -1
  3. package/es/FormFieldGroup/__new-tests__/FormFieldGroup.test.js +4 -4
  4. package/es/FormFieldGroup/index.js +18 -4
  5. package/es/FormFieldLayout/__new-tests__/FormFieldLayout.test.js +10 -8
  6. package/es/FormFieldLayout/index.js +73 -54
  7. package/es/FormFieldLayout/styles.js +109 -10
  8. package/es/FormFieldLayout/theme.js +28 -2
  9. package/es/FormFieldMessages/props.js +3 -2
  10. package/es/FormFieldMessages/styles.js +5 -3
  11. package/es/FormPropTypes.js +6 -0
  12. package/es/index.js +0 -1
  13. package/lib/FormField/index.js +0 -1
  14. package/lib/FormFieldGroup/__new-tests__/FormFieldGroup.test.js +4 -4
  15. package/lib/FormFieldGroup/index.js +18 -4
  16. package/lib/FormFieldLayout/__new-tests__/FormFieldLayout.test.js +9 -7
  17. package/lib/FormFieldLayout/index.js +72 -54
  18. package/lib/FormFieldLayout/styles.js +109 -10
  19. package/lib/FormFieldLayout/theme.js +28 -2
  20. package/lib/FormFieldMessages/props.js +3 -2
  21. package/lib/FormFieldMessages/styles.js +5 -3
  22. package/lib/FormPropTypes.js +6 -0
  23. package/lib/index.js +0 -7
  24. package/package.json +15 -15
  25. package/src/FormField/README.md +31 -3
  26. package/src/FormField/index.tsx +0 -1
  27. package/src/FormFieldGroup/__new-tests__/FormFieldGroup.test.tsx +4 -6
  28. package/src/FormFieldGroup/index.tsx +41 -6
  29. package/src/FormFieldLayout/__new-tests__/FormFieldLayout.test.tsx +6 -8
  30. package/src/FormFieldLayout/index.tsx +78 -92
  31. package/src/FormFieldLayout/props.ts +28 -2
  32. package/src/FormFieldLayout/styles.ts +128 -14
  33. package/src/FormFieldLayout/theme.ts +30 -4
  34. package/src/FormFieldMessages/props.ts +8 -2
  35. package/src/FormFieldMessages/styles.ts +5 -4
  36. package/src/FormPropTypes.ts +4 -0
  37. package/src/index.ts +0 -2
  38. package/tsconfig.build.tsbuildinfo +1 -1
  39. package/types/FormField/index.d.ts.map +1 -1
  40. package/types/FormFieldGroup/index.d.ts +1 -0
  41. package/types/FormFieldGroup/index.d.ts.map +1 -1
  42. package/types/FormFieldLayout/index.d.ts +8 -7
  43. package/types/FormFieldLayout/index.d.ts.map +1 -1
  44. package/types/FormFieldLayout/props.d.ts +27 -3
  45. package/types/FormFieldLayout/props.d.ts.map +1 -1
  46. package/types/FormFieldLayout/styles.d.ts +4 -3
  47. package/types/FormFieldLayout/styles.d.ts.map +1 -1
  48. package/types/FormFieldLayout/theme.d.ts +7 -1
  49. package/types/FormFieldLayout/theme.d.ts.map +1 -1
  50. package/types/FormFieldMessages/index.d.ts +8 -2
  51. package/types/FormFieldMessages/index.d.ts.map +1 -1
  52. package/types/FormFieldMessages/props.d.ts +5 -0
  53. package/types/FormFieldMessages/props.d.ts.map +1 -1
  54. package/types/FormFieldMessages/styles.d.ts +2 -3
  55. package/types/FormFieldMessages/styles.d.ts.map +1 -1
  56. package/types/FormPropTypes.d.ts +3 -0
  57. package/types/FormPropTypes.d.ts.map +1 -1
  58. package/types/index.d.ts +0 -2
  59. package/types/index.d.ts.map +1 -1
  60. package/es/FormFieldLabel/__new-tests__/FormFieldLabel.test.js +0 -66
  61. package/es/FormFieldLabel/index.js +0 -79
  62. package/es/FormFieldLabel/props.js +0 -31
  63. package/es/FormFieldLabel/styles.js +0 -62
  64. package/es/FormFieldLabel/theme.js +0 -52
  65. package/lib/FormFieldLabel/__new-tests__/FormFieldLabel.test.js +0 -68
  66. package/lib/FormFieldLabel/index.js +0 -85
  67. package/lib/FormFieldLabel/props.js +0 -37
  68. package/lib/FormFieldLabel/styles.js +0 -68
  69. package/lib/FormFieldLabel/theme.js +0 -58
  70. package/src/FormFieldLabel/__new-tests__/FormFieldLabel.test.tsx +0 -79
  71. package/src/FormFieldLabel/index.tsx +0 -95
  72. package/src/FormFieldLabel/props.ts +0 -58
  73. package/src/FormFieldLabel/styles.ts +0 -74
  74. package/src/FormFieldLabel/theme.ts +0 -56
  75. package/types/FormFieldLabel/__new-tests__/FormFieldLabel.test.d.ts +0 -2
  76. package/types/FormFieldLabel/__new-tests__/FormFieldLabel.test.d.ts.map +0 -1
  77. package/types/FormFieldLabel/index.d.ts +0 -42
  78. package/types/FormFieldLabel/index.d.ts.map +0 -1
  79. package/types/FormFieldLabel/props.d.ts +0 -15
  80. package/types/FormFieldLabel/props.d.ts.map +0 -1
  81. package/types/FormFieldLabel/styles.d.ts +0 -15
  82. package/types/FormFieldLabel/styles.d.ts.map +0 -1
  83. package/types/FormFieldLabel/theme.d.ts +0 -10
  84. package/types/FormFieldLabel/theme.d.ts.map +0 -1
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- var _react = _interopRequireDefault(require("react"));
5
- var _react2 = require("@testing-library/react");
6
- var _vitest = require("vitest");
7
- var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
8
- require("@testing-library/jest-dom");
9
- var _index = require("../index");
10
- var _FormFieldLabel, _FormFieldLabel2, _FormFieldLabel3;
11
- /*
12
- * The MIT License (MIT)
13
- *
14
- * Copyright (c) 2015 - present Instructure, Inc.
15
- *
16
- * Permission is hereby granted, free of charge, to any person obtaining a copy
17
- * of this software and associated documentation files (the "Software"), to deal
18
- * in the Software without restriction, including without limitation the rights
19
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
- * copies of the Software, and to permit persons to whom the Software is
21
- * furnished to do so, subject to the following conditions:
22
- *
23
- * The above copyright notice and this permission notice shall be included in all
24
- * copies or substantial portions of the Software.
25
- *
26
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
- * SOFTWARE.
33
- */
34
- describe('<FormFieldLabel />', () => {
35
- let consoleWarningMock;
36
- let consoleErrorMock;
37
- beforeEach(() => {
38
- // Mocking console to prevent test output pollution and expect for messages
39
- consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
40
- consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
41
- });
42
- afterEach(() => {
43
- consoleWarningMock.mockRestore();
44
- consoleErrorMock.mockRestore();
45
- });
46
- it('should render', () => {
47
- const _render = (0, _react2.render)(_FormFieldLabel || (_FormFieldLabel = /*#__PURE__*/_react.default.createElement(_index.FormFieldLabel, null, "Foo"))),
48
- container = _render.container;
49
- const formFieldLabel = container.querySelector("span[class$='-formFieldLabel']");
50
- expect(formFieldLabel).toBeInTheDocument();
51
- expect(formFieldLabel).toHaveTextContent('Foo');
52
- });
53
- it('should render as specified via the `as` prop', () => {
54
- const _render2 = (0, _react2.render)(_FormFieldLabel2 || (_FormFieldLabel2 = /*#__PURE__*/_react.default.createElement(_index.FormFieldLabel, {
55
- as: "li"
56
- }, "Foo"))),
57
- container = _render2.container;
58
- const formFieldLabel = container.querySelector('li');
59
- expect(formFieldLabel).toBeInTheDocument();
60
- expect(formFieldLabel).toHaveTextContent('Foo');
61
- });
62
- it('should meet a11y standards', async () => {
63
- const _render3 = (0, _react2.render)(_FormFieldLabel3 || (_FormFieldLabel3 = /*#__PURE__*/_react.default.createElement(_index.FormFieldLabel, null, "Foo"))),
64
- container = _render3.container;
65
- const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
66
- expect(axeCheck).toBe(true);
67
- });
68
- });
@@ -1,85 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = exports.FormFieldLabel = void 0;
8
- var _react = require("react");
9
- var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
10
- var _getElementType = require("@instructure/ui-react-utils/lib/getElementType.js");
11
- var _emotion = require("@instructure/emotion");
12
- var _styles = _interopRequireDefault(require("./styles"));
13
- var _theme = _interopRequireDefault(require("./theme"));
14
- var _props = require("./props");
15
- var _dec, _class, _FormFieldLabel;
16
- /*
17
- * The MIT License (MIT)
18
- *
19
- * Copyright (c) 2015 - present Instructure, Inc.
20
- *
21
- * Permission is hereby granted, free of charge, to any person obtaining a copy
22
- * of this software and associated documentation files (the "Software"), to deal
23
- * in the Software without restriction, including without limitation the rights
24
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25
- * copies of the Software, and to permit persons to whom the Software is
26
- * furnished to do so, subject to the following conditions:
27
- *
28
- * The above copyright notice and this permission notice shall be included in all
29
- * copies or substantial portions of the Software.
30
- *
31
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
- * SOFTWARE.
38
- */
39
- /** @jsx jsx */
40
- /**
41
- ---
42
- parent: FormField
43
- ---
44
-
45
- This is a helper component that is used by most of the custom form
46
- components. In most cases it shouldn't be used directly.
47
-
48
- ```js
49
- ---
50
- type: example
51
- ---
52
- <FormFieldLabel>Hello</FormFieldLabel>
53
- ```
54
-
55
- **/
56
- let FormFieldLabel = exports.FormFieldLabel = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = (_FormFieldLabel = class FormFieldLabel extends _react.Component {
57
- constructor(...args) {
58
- super(...args);
59
- this.ref = null;
60
- this.handleRef = el => {
61
- this.ref = el;
62
- };
63
- }
64
- componentDidMount() {
65
- var _this$props$makeStyle, _this$props;
66
- (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
67
- }
68
- componentDidUpdate() {
69
- var _this$props$makeStyle2, _this$props2;
70
- (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
71
- }
72
- render() {
73
- const ElementType = (0, _getElementType.getElementType)(FormFieldLabel, this.props);
74
- const _this$props3 = this.props,
75
- styles = _this$props3.styles,
76
- children = _this$props3.children;
77
- return (0, _emotion.jsx)(ElementType, Object.assign({}, (0, _omitProps.omitProps)(this.props, FormFieldLabel.allowedProps), {
78
- css: styles === null || styles === void 0 ? void 0 : styles.formFieldLabel,
79
- ref: this.handleRef
80
- }), children);
81
- }
82
- }, _FormFieldLabel.displayName = "FormFieldLabel", _FormFieldLabel.componentId = 'FormFieldLabel', _FormFieldLabel.propTypes = _props.propTypes, _FormFieldLabel.allowedProps = _props.allowedProps, _FormFieldLabel.defaultProps = {
83
- as: 'span'
84
- }, _FormFieldLabel)) || _class);
85
- var _default = exports.default = FormFieldLabel;
@@ -1,37 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.propTypes = exports.allowedProps = void 0;
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
- /*
10
- * The MIT License (MIT)
11
- *
12
- * Copyright (c) 2015 - present Instructure, Inc.
13
- *
14
- * Permission is hereby granted, free of charge, to any person obtaining a copy
15
- * of this software and associated documentation files (the "Software"), to deal
16
- * in the Software without restriction, including without limitation the rights
17
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
- * copies of the Software, and to permit persons to whom the Software is
19
- * furnished to do so, subject to the following conditions:
20
- *
21
- * The above copyright notice and this permission notice shall be included in all
22
- * copies or substantial portions of the Software.
23
- *
24
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
- * SOFTWARE.
31
- */
32
-
33
- const propTypes = exports.propTypes = {
34
- children: _propTypes.default.node.isRequired,
35
- as: _propTypes.default.elementType
36
- };
37
- const allowedProps = exports.allowedProps = ['as', 'children'];
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _hasVisibleChildren = require("@instructure/ui-a11y-utils/lib/hasVisibleChildren.js");
8
- /*
9
- * The MIT License (MIT)
10
- *
11
- * Copyright (c) 2015 - present Instructure, Inc.
12
- *
13
- * Permission is hereby granted, free of charge, to any person obtaining a copy
14
- * of this software and associated documentation files (the "Software"), to deal
15
- * in the Software without restriction, including without limitation the rights
16
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
- * copies of the Software, and to permit persons to whom the Software is
18
- * furnished to do so, subject to the following conditions:
19
- *
20
- * The above copyright notice and this permission notice shall be included in all
21
- * copies or substantial portions of the Software.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
- * SOFTWARE.
30
- */
31
-
32
- /**
33
- * ---
34
- * private: true
35
- * ---
36
- * Generates the style object from the theme and provided additional information
37
- * @param {Object} componentTheme The theme variable object.
38
- * @param {Object} props the props of the component, the style is applied to
39
- * @param {Object} state the state of the component, the style is applied to
40
- * @return {Object} The final style object, which will be used in the component
41
- */
42
- const generateStyle = (componentTheme, props) => {
43
- const children = props.children;
44
- const hasContent = (0, _hasVisibleChildren.hasVisibleChildren)(children);
45
- const labelStyles = {
46
- all: 'initial',
47
- display: 'block',
48
- ...(hasContent && {
49
- color: componentTheme.color,
50
- fontFamily: componentTheme.fontFamily,
51
- fontWeight: componentTheme.fontWeight,
52
- fontSize: componentTheme.fontSize,
53
- lineHeight: componentTheme.lineHeight,
54
- margin: 0,
55
- textAlign: 'inherit'
56
- })
57
- };
58
- return {
59
- formFieldLabel: {
60
- label: 'formFieldLabel',
61
- ...labelStyles,
62
- // NOTE: needs separate groups for `:is()` and `:-webkit-any()` because of css selector group validation (see https://www.w3.org/TR/selectors-3/#grouping)
63
- '&:is(label)': labelStyles,
64
- '&:-webkit-any(label)': labelStyles
65
- }
66
- };
67
- };
68
- var _default = exports.default = generateStyle;
@@ -1,58 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- /*
8
- * The MIT License (MIT)
9
- *
10
- * Copyright (c) 2015 - present Instructure, Inc.
11
- *
12
- * Permission is hereby granted, free of charge, to any person obtaining a copy
13
- * of this software and associated documentation files (the "Software"), to deal
14
- * in the Software without restriction, including without limitation the rights
15
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
- * copies of the Software, and to permit persons to whom the Software is
17
- * furnished to do so, subject to the following conditions:
18
- *
19
- * The above copyright notice and this permission notice shall be included in all
20
- * copies or substantial portions of the Software.
21
- *
22
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
- * SOFTWARE.
29
- */
30
-
31
- /**
32
- * Generates the theme object for the component from the theme and provided additional information
33
- * @param {Object} theme The actual theme object.
34
- * @return {Object} The final theme object with the overrides and component variables
35
- */
36
- const generateComponentTheme = theme => {
37
- var _colors$contrasts;
38
- const colors = theme.colors,
39
- typography = theme.typography,
40
- themeName = theme.key;
41
- const themeSpecificStyle = {
42
- canvas: {
43
- color: theme['ic-brand-font-color-dark']
44
- }
45
- };
46
- const componentVariables = {
47
- color: colors === null || colors === void 0 ? void 0 : (_colors$contrasts = colors.contrasts) === null || _colors$contrasts === void 0 ? void 0 : _colors$contrasts.grey125125,
48
- fontFamily: typography === null || typography === void 0 ? void 0 : typography.fontFamily,
49
- fontWeight: typography === null || typography === void 0 ? void 0 : typography.fontWeightBold,
50
- fontSize: typography === null || typography === void 0 ? void 0 : typography.fontSizeMedium,
51
- lineHeight: typography === null || typography === void 0 ? void 0 : typography.lineHeightFit
52
- };
53
- return {
54
- ...componentVariables,
55
- ...themeSpecificStyle[themeName]
56
- };
57
- };
58
- var _default = exports.default = generateComponentTheme;
@@ -1,79 +0,0 @@
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 { render } from '@testing-library/react'
27
- import { vi } from 'vitest'
28
- import { runAxeCheck } from '@instructure/ui-axe-check'
29
- import '@testing-library/jest-dom'
30
-
31
- import { FormFieldLabel } from '../index'
32
-
33
- describe('<FormFieldLabel />', () => {
34
- let consoleWarningMock: ReturnType<typeof vi.spyOn>
35
- let consoleErrorMock: ReturnType<typeof vi.spyOn>
36
-
37
- beforeEach(() => {
38
- // Mocking console to prevent test output pollution and expect for messages
39
- consoleWarningMock = vi
40
- .spyOn(console, 'warn')
41
- .mockImplementation(() => {}) as any
42
- consoleErrorMock = vi
43
- .spyOn(console, 'error')
44
- .mockImplementation(() => {}) as any
45
- })
46
-
47
- afterEach(() => {
48
- consoleWarningMock.mockRestore()
49
- consoleErrorMock.mockRestore()
50
- })
51
-
52
- it('should render', () => {
53
- const { container } = render(<FormFieldLabel>Foo</FormFieldLabel>)
54
-
55
- const formFieldLabel = container.querySelector(
56
- "span[class$='-formFieldLabel']"
57
- )
58
-
59
- expect(formFieldLabel).toBeInTheDocument()
60
- expect(formFieldLabel).toHaveTextContent('Foo')
61
- })
62
-
63
- it('should render as specified via the `as` prop', () => {
64
- const { container } = render(<FormFieldLabel as="li">Foo</FormFieldLabel>)
65
-
66
- const formFieldLabel = container.querySelector('li')
67
-
68
- expect(formFieldLabel).toBeInTheDocument()
69
- expect(formFieldLabel).toHaveTextContent('Foo')
70
- })
71
-
72
- it('should meet a11y standards', async () => {
73
- const { container } = render(<FormFieldLabel>Foo</FormFieldLabel>)
74
-
75
- const axeCheck = await runAxeCheck(container)
76
-
77
- expect(axeCheck).toBe(true)
78
- })
79
- })
@@ -1,95 +0,0 @@
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
- /** @jsx jsx */
26
- import { Component } from 'react'
27
-
28
- import { omitProps, getElementType } from '@instructure/ui-react-utils'
29
- import { withStyle, jsx } from '@instructure/emotion'
30
-
31
- import generateStyle from './styles'
32
- import generateComponentTheme from './theme'
33
-
34
- import { propTypes, allowedProps } from './props'
35
- import type { FormFieldLabelProps } from './props'
36
-
37
- /**
38
- ---
39
- parent: FormField
40
- ---
41
-
42
- This is a helper component that is used by most of the custom form
43
- components. In most cases it shouldn't be used directly.
44
-
45
- ```js
46
- ---
47
- type: example
48
- ---
49
- <FormFieldLabel>Hello</FormFieldLabel>
50
- ```
51
-
52
- **/
53
- @withStyle(generateStyle, generateComponentTheme)
54
- class FormFieldLabel extends Component<FormFieldLabelProps> {
55
- static readonly componentId = 'FormFieldLabel'
56
-
57
- static propTypes = propTypes
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 }
@@ -1,58 +0,0 @@
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 PropTypes from 'prop-types'
26
-
27
- import type {
28
- AsElementType,
29
- PropValidators,
30
- FormFieldLabelTheme,
31
- OtherHTMLAttributes
32
- } from '@instructure/shared-types'
33
- import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
34
-
35
- type FormFieldLabelOwnProps = {
36
- children: React.ReactNode
37
- as?: AsElementType
38
- }
39
-
40
- type PropKeys = keyof FormFieldLabelOwnProps
41
-
42
- type AllowedPropKeys = Readonly<Array<PropKeys>>
43
-
44
- type FormFieldLabelProps = FormFieldLabelOwnProps &
45
- WithStyleProps<FormFieldLabelTheme, FormFieldLabelStyle> &
46
- OtherHTMLAttributes<FormFieldLabelOwnProps>
47
-
48
- type FormFieldLabelStyle = ComponentStyle<'formFieldLabel'>
49
-
50
- const propTypes: PropValidators<PropKeys> = {
51
- children: PropTypes.node.isRequired,
52
- as: PropTypes.elementType
53
- }
54
-
55
- const allowedProps: AllowedPropKeys = ['as', 'children']
56
-
57
- export type { FormFieldLabelProps, FormFieldLabelStyle }
58
- export { propTypes, allowedProps }
@@ -1,74 +0,0 @@
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
@@ -1,56 +0,0 @@
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