@instructure/ui-form-field 10.11.1-snapshot-17 → 10.12.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.
package/CHANGELOG.md CHANGED
@@ -3,9 +3,12 @@
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.11.1-snapshot-17](https://github.com/instructure/instructure-ui/compare/v10.11.0...v10.11.1-snapshot-17) (2025-02-21)
6
+ # [10.12.0](https://github.com/instructure/instructure-ui/compare/v10.11.0...v10.12.0) (2025-02-24)
7
7
 
8
- **Note:** Version bump only for package @instructure/ui-form-field
8
+
9
+ ### Features
10
+
11
+ * **many:** introduce new spacing tokens; add margin prop for more components ([048c902](https://github.com/instructure/instructure-ui/commit/048c902406c00611cd117fb2fb8164a6eba62fb8))
9
12
 
10
13
 
11
14
 
@@ -49,7 +49,8 @@ class FormField extends Component {
49
49
  vAlign: this.props.vAlign,
50
50
  as: "label",
51
51
  htmlFor: this.props.id,
52
- elementRef: this.handleRef
52
+ elementRef: this.handleRef,
53
+ margin: this.props.margin
53
54
  }));
54
55
  }
55
56
  }
@@ -36,7 +36,8 @@ const propTypes = {
36
36
  vAlign: PropTypes.oneOf(['top', 'middle', 'bottom']),
37
37
  width: PropTypes.string,
38
38
  inputContainerRef: PropTypes.func,
39
- elementRef: PropTypes.func
39
+ elementRef: PropTypes.func,
40
+ margin: PropTypes.string
40
41
  };
41
- const allowedProps = ['label', 'id', 'messages', 'messagesId', 'children', 'inline', 'layout', 'labelAlign', 'vAlign', 'width', 'inputContainerRef', 'elementRef'];
42
+ const allowedProps = ['label', 'id', 'messages', 'messagesId', 'children', 'inline', 'layout', 'labelAlign', 'vAlign', 'width', 'inputContainerRef', 'elementRef', 'margin'];
42
43
  export { propTypes, allowedProps };
@@ -36,12 +36,14 @@ import { FormFieldLabel } from '../FormFieldLabel';
36
36
  import { FormFieldMessages } from '../FormFieldMessages';
37
37
  import generateStyle from './styles';
38
38
  import { propTypes, allowedProps } from './props';
39
+ import generateComponentTheme from './theme';
40
+
39
41
  /**
40
42
  ---
41
43
  parent: FormField
42
44
  ---
43
45
  **/
44
- let FormFieldLayout = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, null), _dec(_class = _dec2(_class = (_FormFieldLayout = class FormFieldLayout extends Component {
46
+ let FormFieldLayout = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec(_class = _dec2(_class = (_FormFieldLayout = class FormFieldLayout extends Component {
45
47
  constructor(props) {
46
48
  super(props);
47
49
  this._messagesId = void 0;
@@ -38,9 +38,10 @@ const propTypes = {
38
38
  width: PropTypes.string,
39
39
  inputContainerRef: PropTypes.func,
40
40
  elementRef: PropTypes.func,
41
- isGroup: PropTypes.bool
41
+ isGroup: PropTypes.bool,
42
+ margin: PropTypes.string
42
43
  };
43
- const allowedProps = ['label', 'id', 'as', 'messages', 'messagesId', 'children', 'inline', 'layout', 'labelAlign', 'width', 'inputContainerRef', 'elementRef'
44
+ const allowedProps = ['label', 'id', 'as', 'messages', 'messagesId', 'children', 'inline', 'layout', 'labelAlign', 'width', 'inputContainerRef', 'elementRef', 'margin'
44
45
 
45
46
  // added vAlign because FormField and FormFieldGroup passes it, but not adding
46
47
  // it to allowedProps to prevent it from getting passed through accidentally
@@ -22,6 +22,7 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
+ import { mapSpacingToShorthand } from '@instructure/emotion';
25
26
  /**
26
27
  * ---
27
28
  * private: true
@@ -32,8 +33,11 @@
32
33
  * @param {Object} state the state of the component, the style is applied to
33
34
  * @return {Object} The final style object, which will be used in the component
34
35
  */
35
- const generateStyle = (_componentTheme, props) => {
36
- const inline = props.inline;
36
+ const generateStyle = (componentTheme, props) => {
37
+ const inline = props.inline,
38
+ margin = props.margin;
39
+ const spacing = componentTheme.spacing;
40
+ const cssMargin = mapSpacingToShorthand(margin, spacing);
37
41
  return {
38
42
  groupErrorMessage: {
39
43
  margin: '0.5rem 0'
@@ -43,7 +47,7 @@ const generateStyle = (_componentTheme, props) => {
43
47
  all: 'initial',
44
48
  border: '0',
45
49
  padding: '0',
46
- margin: '0',
50
+ margin: cssMargin,
47
51
  minWidth: '0',
48
52
  direction: 'inherit',
49
53
  textAlign: 'start',
@@ -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
+ const generateComponentTheme = theme => {
26
+ const spacing = theme.spacing;
27
+ return {
28
+ spacing
29
+ };
30
+ };
31
+ export default generateComponentTheme;
@@ -57,7 +57,8 @@ class FormField extends _react.Component {
57
57
  vAlign: this.props.vAlign,
58
58
  as: "label",
59
59
  htmlFor: this.props.id,
60
- elementRef: this.handleRef
60
+ elementRef: this.handleRef,
61
+ margin: this.props.margin
61
62
  }));
62
63
  }
63
64
  }
@@ -43,6 +43,7 @@ const propTypes = exports.propTypes = {
43
43
  vAlign: _propTypes.default.oneOf(['top', 'middle', 'bottom']),
44
44
  width: _propTypes.default.string,
45
45
  inputContainerRef: _propTypes.default.func,
46
- elementRef: _propTypes.default.func
46
+ elementRef: _propTypes.default.func,
47
+ margin: _propTypes.default.string
47
48
  };
48
- const allowedProps = exports.allowedProps = ['label', 'id', 'messages', 'messagesId', 'children', 'inline', 'layout', 'labelAlign', 'vAlign', 'width', 'inputContainerRef', 'elementRef'];
49
+ const allowedProps = exports.allowedProps = ['label', 'id', 'messages', 'messagesId', 'children', 'inline', 'layout', 'labelAlign', 'vAlign', 'width', 'inputContainerRef', 'elementRef', 'margin'];
@@ -19,6 +19,7 @@ var _FormFieldLabel = require("../FormFieldLabel");
19
19
  var _FormFieldMessages = require("../FormFieldMessages");
20
20
  var _styles = _interopRequireDefault(require("./styles"));
21
21
  var _props = require("./props");
22
+ var _theme = _interopRequireDefault(require("./theme"));
22
23
  const _excluded = ["makeStyles", "styles", "messages", "isGroup"];
23
24
  var _dec, _dec2, _class, _FormFieldLayout;
24
25
  /*
@@ -50,7 +51,7 @@ var _dec, _dec2, _class, _FormFieldLayout;
50
51
  parent: FormField
51
52
  ---
52
53
  **/
53
- let FormFieldLayout = exports.FormFieldLayout = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default, null), _dec(_class = _dec2(_class = (_FormFieldLayout = class FormFieldLayout extends _react.Component {
54
+ let FormFieldLayout = exports.FormFieldLayout = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = _dec2(_class = (_FormFieldLayout = class FormFieldLayout extends _react.Component {
54
55
  constructor(props) {
55
56
  super(props);
56
57
  this._messagesId = void 0;
@@ -45,9 +45,10 @@ const propTypes = exports.propTypes = {
45
45
  width: _propTypes.default.string,
46
46
  inputContainerRef: _propTypes.default.func,
47
47
  elementRef: _propTypes.default.func,
48
- isGroup: _propTypes.default.bool
48
+ isGroup: _propTypes.default.bool,
49
+ margin: _propTypes.default.string
49
50
  };
50
- const allowedProps = exports.allowedProps = ['label', 'id', 'as', 'messages', 'messagesId', 'children', 'inline', 'layout', 'labelAlign', 'width', 'inputContainerRef', 'elementRef'
51
+ const allowedProps = exports.allowedProps = ['label', 'id', 'as', 'messages', 'messagesId', 'children', 'inline', 'layout', 'labelAlign', 'width', 'inputContainerRef', 'elementRef', 'margin'
51
52
 
52
53
  // added vAlign because FormField and FormFieldGroup passes it, but not adding
53
54
  // it to allowedProps to prevent it from getting passed through accidentally
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _emotion = require("@instructure/emotion");
7
8
  /*
8
9
  * The MIT License (MIT)
9
10
  *
@@ -38,8 +39,11 @@ exports.default = void 0;
38
39
  * @param {Object} state the state of the component, the style is applied to
39
40
  * @return {Object} The final style object, which will be used in the component
40
41
  */
41
- const generateStyle = (_componentTheme, props) => {
42
- const inline = props.inline;
42
+ const generateStyle = (componentTheme, props) => {
43
+ const inline = props.inline,
44
+ margin = props.margin;
45
+ const spacing = componentTheme.spacing;
46
+ const cssMargin = (0, _emotion.mapSpacingToShorthand)(margin, spacing);
43
47
  return {
44
48
  groupErrorMessage: {
45
49
  margin: '0.5rem 0'
@@ -49,7 +53,7 @@ const generateStyle = (_componentTheme, props) => {
49
53
  all: 'initial',
50
54
  border: '0',
51
55
  padding: '0',
52
- margin: '0',
56
+ margin: cssMargin,
53
57
  minWidth: '0',
54
58
  direction: 'inherit',
55
59
  textAlign: 'start',
@@ -0,0 +1,37 @@
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
+ const generateComponentTheme = theme => {
32
+ const spacing = theme.spacing;
33
+ return {
34
+ spacing
35
+ };
36
+ };
37
+ var _default = exports.default = generateComponentTheme;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-form-field",
3
- "version": "10.11.1-snapshot-17",
3
+ "version": "10.12.0",
4
4
  "description": "Form layout components.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,26 +23,26 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-axe-check": "10.11.1-snapshot-17",
27
- "@instructure/ui-babel-preset": "10.11.1-snapshot-17",
28
- "@instructure/ui-test-utils": "10.11.1-snapshot-17",
29
- "@instructure/ui-themes": "10.11.1-snapshot-17",
26
+ "@instructure/ui-axe-check": "10.12.0",
27
+ "@instructure/ui-babel-preset": "10.12.0",
28
+ "@instructure/ui-test-utils": "10.12.0",
29
+ "@instructure/ui-themes": "10.12.0",
30
30
  "@testing-library/jest-dom": "^6.6.3",
31
31
  "@testing-library/react": "^16.0.1",
32
32
  "vitest": "^2.1.8"
33
33
  },
34
34
  "dependencies": {
35
35
  "@babel/runtime": "^7.26.0",
36
- "@instructure/console": "10.11.1-snapshot-17",
37
- "@instructure/emotion": "10.11.1-snapshot-17",
38
- "@instructure/shared-types": "10.11.1-snapshot-17",
39
- "@instructure/ui-a11y-content": "10.11.1-snapshot-17",
40
- "@instructure/ui-a11y-utils": "10.11.1-snapshot-17",
41
- "@instructure/ui-grid": "10.11.1-snapshot-17",
42
- "@instructure/ui-icons": "10.11.1-snapshot-17",
43
- "@instructure/ui-react-utils": "10.11.1-snapshot-17",
44
- "@instructure/ui-utils": "10.11.1-snapshot-17",
45
- "@instructure/uid": "10.11.1-snapshot-17",
36
+ "@instructure/console": "10.12.0",
37
+ "@instructure/emotion": "10.12.0",
38
+ "@instructure/shared-types": "10.12.0",
39
+ "@instructure/ui-a11y-content": "10.12.0",
40
+ "@instructure/ui-a11y-utils": "10.12.0",
41
+ "@instructure/ui-grid": "10.12.0",
42
+ "@instructure/ui-icons": "10.12.0",
43
+ "@instructure/ui-react-utils": "10.12.0",
44
+ "@instructure/ui-utils": "10.12.0",
45
+ "@instructure/uid": "10.12.0",
46
46
  "prop-types": "^15.8.1"
47
47
  },
48
48
  "peerDependencies": {
@@ -70,6 +70,7 @@ class FormField extends Component<FormFieldProps> {
70
70
  as="label"
71
71
  htmlFor={this.props.id}
72
72
  elementRef={this.handleRef}
73
+ margin={this.props.margin}
73
74
  />
74
75
  )
75
76
  }
@@ -32,6 +32,7 @@ import type {
32
32
  PropValidators
33
33
  } from '@instructure/shared-types'
34
34
  import type { FormMessage } from '../FormPropTypes'
35
+ import type { Spacing } from '@instructure/emotion'
35
36
 
36
37
  type FormFieldOwnProps = {
37
38
  label: React.ReactNode
@@ -62,6 +63,11 @@ type FormFieldOwnProps = {
62
63
  * provides a reference to the underlying html root element
63
64
  */
64
65
  elementRef?: (element: Element | null) => void
66
+
67
+ /**
68
+ * Margin around the component. Accepts a `Spacing` token. See token values and example usage in [this guide](https://instructure.design/#layout-spacing).
69
+ */
70
+ margin?: Spacing
65
71
  }
66
72
 
67
73
  type PropKeys = keyof FormFieldOwnProps
@@ -82,7 +88,8 @@ const propTypes: PropValidators<PropKeys> = {
82
88
  vAlign: PropTypes.oneOf(['top', 'middle', 'bottom']),
83
89
  width: PropTypes.string,
84
90
  inputContainerRef: PropTypes.func,
85
- elementRef: PropTypes.func
91
+ elementRef: PropTypes.func,
92
+ margin: PropTypes.string
86
93
  }
87
94
 
88
95
  const allowedProps: AllowedPropKeys = [
@@ -97,7 +104,8 @@ const allowedProps: AllowedPropKeys = [
97
104
  'vAlign',
98
105
  'width',
99
106
  'inputContainerRef',
100
- 'elementRef'
107
+ 'elementRef',
108
+ 'margin'
101
109
  ]
102
110
 
103
111
  export type { FormFieldOwnProps, FormFieldProps }
@@ -44,6 +44,7 @@ import generateStyle from './styles'
44
44
 
45
45
  import { propTypes, allowedProps } from './props'
46
46
  import type { FormFieldLayoutProps } from './props'
47
+ import generateComponentTheme from './theme'
47
48
 
48
49
  /**
49
50
  ---
@@ -51,7 +52,7 @@ parent: FormField
51
52
  ---
52
53
  **/
53
54
  @withDeterministicId()
54
- @withStyle(generateStyle, null)
55
+ @withStyle(generateStyle, generateComponentTheme)
55
56
  class FormFieldLayout extends Component<FormFieldLayoutProps> {
56
57
  static readonly componentId = 'FormFieldLayout'
57
58
 
@@ -31,7 +31,11 @@ import type {
31
31
  OtherHTMLAttributes,
32
32
  PropValidators
33
33
  } from '@instructure/shared-types'
34
- import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
34
+ import type {
35
+ WithStyleProps,
36
+ ComponentStyle,
37
+ Spacing
38
+ } from '@instructure/emotion'
35
39
  import type { FormMessage } from '../FormPropTypes'
36
40
  import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
37
41
 
@@ -68,6 +72,11 @@ type FormFieldLayoutOwnProps = {
68
72
  */
69
73
  elementRef?: (element: Element | null) => void
70
74
  isGroup?: boolean
75
+
76
+ /**
77
+ * Margin around the component. Accepts a `Spacing` token. See token values and example usage in [this guide](https://instructure.design/#layout-spacing).
78
+ */
79
+ margin?: Spacing
71
80
  }
72
81
 
73
82
  type PropKeys = keyof FormFieldLayoutOwnProps
@@ -97,7 +106,8 @@ const propTypes: PropValidators<PropKeys> = {
97
106
  width: PropTypes.string,
98
107
  inputContainerRef: PropTypes.func,
99
108
  elementRef: PropTypes.func,
100
- isGroup: PropTypes.bool
109
+ isGroup: PropTypes.bool,
110
+ margin: PropTypes.string
101
111
  }
102
112
 
103
113
  const allowedProps: AllowedPropKeys = [
@@ -112,7 +122,8 @@ const allowedProps: AllowedPropKeys = [
112
122
  'labelAlign',
113
123
  'width',
114
124
  'inputContainerRef',
115
- 'elementRef'
125
+ 'elementRef',
126
+ 'margin'
116
127
 
117
128
  // added vAlign because FormField and FormFieldGroup passes it, but not adding
118
129
  // it to allowedProps to prevent it from getting passed through accidentally
@@ -22,6 +22,7 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
+ import { mapSpacingToShorthand } from '@instructure/emotion'
25
26
  import type { FormFieldLayoutProps, FormFieldLayoutStyle } from './props'
26
27
 
27
28
  /**
@@ -35,21 +36,23 @@ import type { FormFieldLayoutProps, FormFieldLayoutStyle } from './props'
35
36
  * @return {Object} The final style object, which will be used in the component
36
37
  */
37
38
  const generateStyle = (
38
- _componentTheme: null,
39
+ componentTheme: any,
39
40
  props: FormFieldLayoutProps
40
41
  ): FormFieldLayoutStyle => {
41
- const { inline } = props
42
+ const { inline, margin } = props
43
+ const { spacing } = componentTheme
42
44
 
45
+ const cssMargin = mapSpacingToShorthand(margin, spacing)
43
46
  return {
44
47
  groupErrorMessage: {
45
- margin: '0.5rem 0',
48
+ margin: '0.5rem 0'
46
49
  },
47
50
  formFieldLayout: {
48
51
  label: 'formFieldLayout',
49
52
  all: 'initial',
50
53
  border: '0',
51
54
  padding: '0',
52
- margin: '0',
55
+ margin: cssMargin,
53
56
  minWidth: '0',
54
57
  direction: 'inherit',
55
58
  textAlign: 'start',
@@ -0,0 +1,33 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import type { Theme } from '@instructure/ui-themes'
26
+
27
+ const generateComponentTheme = (theme: Theme): any => {
28
+ const { spacing } = theme
29
+
30
+ return { spacing }
31
+ }
32
+
33
+ export default generateComponentTheme