@instructure/ui-form-field 10.12.1-snapshot-1 → 10.12.1-snapshot-3

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