@ohos-ports/instructure-ui-toggle-details 11.7.5-beta.1

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 (91) hide show
  1. package/CHANGELOG.md +1323 -0
  2. package/LICENSE.md +28 -0
  3. package/README.md +42 -0
  4. package/es/ToggleDetails/v1/index.js +177 -0
  5. package/es/ToggleDetails/v1/props.js +26 -0
  6. package/es/ToggleDetails/v1/styles.js +196 -0
  7. package/es/ToggleDetails/v1/theme.js +75 -0
  8. package/es/ToggleDetails/v2/index.js +181 -0
  9. package/es/ToggleDetails/v2/props.js +26 -0
  10. package/es/ToggleDetails/v2/styles.js +188 -0
  11. package/es/ToggleGroup/v1/index.js +172 -0
  12. package/es/ToggleGroup/v1/props.js +26 -0
  13. package/es/ToggleGroup/v1/styles.js +40 -0
  14. package/es/ToggleGroup/v1/theme.js +41 -0
  15. package/es/ToggleGroup/v2/index.js +178 -0
  16. package/es/ToggleGroup/v2/props.js +26 -0
  17. package/es/ToggleGroup/v2/styles.js +40 -0
  18. package/es/exports/a.js +26 -0
  19. package/es/exports/b.js +26 -0
  20. package/lib/ToggleDetails/v1/index.js +184 -0
  21. package/lib/ToggleDetails/v1/props.js +31 -0
  22. package/lib/ToggleDetails/v1/styles.js +202 -0
  23. package/lib/ToggleDetails/v1/theme.js +81 -0
  24. package/lib/ToggleDetails/v2/index.js +187 -0
  25. package/lib/ToggleDetails/v2/props.js +31 -0
  26. package/lib/ToggleDetails/v2/styles.js +194 -0
  27. package/lib/ToggleGroup/v1/index.js +180 -0
  28. package/lib/ToggleGroup/v1/props.js +31 -0
  29. package/lib/ToggleGroup/v1/styles.js +46 -0
  30. package/lib/ToggleGroup/v1/theme.js +47 -0
  31. package/lib/ToggleGroup/v2/index.js +185 -0
  32. package/lib/ToggleGroup/v2/props.js +31 -0
  33. package/lib/ToggleGroup/v2/styles.js +46 -0
  34. package/lib/exports/a.js +19 -0
  35. package/lib/exports/b.js +19 -0
  36. package/lib/package.json +1 -0
  37. package/package.json +94 -0
  38. package/src/ToggleDetails/v1/README.md +233 -0
  39. package/src/ToggleDetails/v1/index.tsx +204 -0
  40. package/src/ToggleDetails/v1/props.ts +114 -0
  41. package/src/ToggleDetails/v1/styles.ts +190 -0
  42. package/src/ToggleDetails/v1/theme.ts +80 -0
  43. package/src/ToggleDetails/v2/README.md +233 -0
  44. package/src/ToggleDetails/v2/index.tsx +206 -0
  45. package/src/ToggleDetails/v2/props.ts +115 -0
  46. package/src/ToggleDetails/v2/styles.ts +188 -0
  47. package/src/ToggleGroup/v1/README.md +93 -0
  48. package/src/ToggleGroup/v1/index.tsx +206 -0
  49. package/src/ToggleGroup/v1/props.ts +115 -0
  50. package/src/ToggleGroup/v1/styles.ts +47 -0
  51. package/src/ToggleGroup/v1/theme.ts +43 -0
  52. package/src/ToggleGroup/v2/README.md +93 -0
  53. package/src/ToggleGroup/v2/index.tsx +214 -0
  54. package/src/ToggleGroup/v2/props.ts +115 -0
  55. package/src/ToggleGroup/v2/styles.ts +47 -0
  56. package/src/exports/a.ts +29 -0
  57. package/src/exports/b.ts +29 -0
  58. package/tsconfig.build.json +26 -0
  59. package/tsconfig.json +4 -0
  60. package/types/ToggleDetails/v1/index.d.ts +56 -0
  61. package/types/ToggleDetails/v1/index.d.ts.map +1 -0
  62. package/types/ToggleDetails/v1/props.d.ts +55 -0
  63. package/types/ToggleDetails/v1/props.d.ts.map +1 -0
  64. package/types/ToggleDetails/v1/styles.d.ts +15 -0
  65. package/types/ToggleDetails/v1/styles.d.ts.map +1 -0
  66. package/types/ToggleDetails/v1/theme.d.ts +10 -0
  67. package/types/ToggleDetails/v1/theme.d.ts.map +1 -0
  68. package/types/ToggleDetails/v2/index.d.ts +55 -0
  69. package/types/ToggleDetails/v2/index.d.ts.map +1 -0
  70. package/types/ToggleDetails/v2/props.d.ts +56 -0
  71. package/types/ToggleDetails/v2/props.d.ts.map +1 -0
  72. package/types/ToggleDetails/v2/styles.d.ts +16 -0
  73. package/types/ToggleDetails/v2/styles.d.ts.map +1 -0
  74. package/types/ToggleGroup/v1/index.d.ts +55 -0
  75. package/types/ToggleGroup/v1/index.d.ts.map +1 -0
  76. package/types/ToggleGroup/v1/props.d.ts +65 -0
  77. package/types/ToggleGroup/v1/props.d.ts.map +1 -0
  78. package/types/ToggleGroup/v1/styles.d.ts +15 -0
  79. package/types/ToggleGroup/v1/styles.d.ts.map +1 -0
  80. package/types/ToggleGroup/v1/theme.d.ts +10 -0
  81. package/types/ToggleGroup/v1/theme.d.ts.map +1 -0
  82. package/types/ToggleGroup/v2/index.d.ts +54 -0
  83. package/types/ToggleGroup/v2/index.d.ts.map +1 -0
  84. package/types/ToggleGroup/v2/props.d.ts +66 -0
  85. package/types/ToggleGroup/v2/props.d.ts.map +1 -0
  86. package/types/ToggleGroup/v2/styles.d.ts +15 -0
  87. package/types/ToggleGroup/v2/styles.d.ts.map +1 -0
  88. package/types/exports/a.d.ts +5 -0
  89. package/types/exports/a.d.ts.map +1 -0
  90. package/types/exports/b.d.ts +5 -0
  91. package/types/exports/b.d.ts.map +1 -0
@@ -0,0 +1,181 @@
1
+ var _dec, _class;
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 { Component, createRef } from 'react';
27
+ import { Button } from '@instructure/ui-buttons/latest';
28
+ import { ChevronRightInstUIIcon, ChevronDownInstUIIcon } from '@instructure/ui-icons';
29
+ import { Expandable } from '@instructure/ui-expandable/latest';
30
+ import { omitProps, pickProps } from '@instructure/ui-react-utils';
31
+ import { isActiveElement } from '@instructure/ui-dom-utils';
32
+ import { withStyleNew } from '@instructure/emotion';
33
+ import generateStyle from './styles.js';
34
+ import { allowedProps } from './props.js';
35
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
36
+ /**
37
+ ---
38
+ category: components
39
+ ---
40
+ **/
41
+ let ToggleDetails = (_dec = withStyleNew(generateStyle), _dec(_class = class ToggleDetails extends Component {
42
+ static displayName = 'ToggleDetails';
43
+ static componentId = 'ToggleDetails';
44
+ static allowedProps = allowedProps;
45
+ static defaultProps = {
46
+ variant: 'default',
47
+ size: 'medium',
48
+ fluidWidth: false,
49
+ icon: ChevronRightInstUIIcon,
50
+ iconExpanded: ChevronDownInstUIIcon,
51
+ iconPosition: 'start',
52
+ defaultExpanded: false,
53
+ children: null
54
+ };
55
+ _buttonNode = null;
56
+ ref = /*#__PURE__*/createRef();
57
+
58
+ // TODO this solution was generated with Gemini, should be tested if it works as fine as before
59
+ setButtonRef = node => {
60
+ this._buttonNode = node;
61
+ };
62
+ get focused() {
63
+ return isActiveElement(this._buttonNode);
64
+ }
65
+ focus() {
66
+ this._buttonNode?.focus();
67
+ }
68
+ componentDidMount() {
69
+ this.props.makeStyles?.();
70
+ }
71
+ componentDidUpdate() {
72
+ this.props.makeStyles?.();
73
+ }
74
+ renderSummary(expanded) {
75
+ const {
76
+ summary,
77
+ iconPosition
78
+ } = this.props;
79
+ return _jsxs("span", {
80
+ css: this.props.styles?.summary,
81
+ children: [iconPosition === 'start' && this.renderIcon(expanded), _jsx("span", {
82
+ css: this.props.styles?.summaryText,
83
+ children: summary
84
+ }), iconPosition === 'end' && this.renderIcon(expanded)]
85
+ });
86
+ }
87
+ renderToggle(toggleProps, expanded) {
88
+ const {
89
+ variant
90
+ } = this.props;
91
+ const tProps = this.props.children ? toggleProps : {
92
+ onClick: toggleProps.onClick
93
+ };
94
+ const props = {
95
+ ...omitProps(this.props, ToggleDetails.allowedProps),
96
+ ...tProps,
97
+ children: this.renderSummary(expanded)
98
+ };
99
+ const summary = this.renderSummary(expanded);
100
+ if (variant === 'filled') {
101
+ return _jsx(Button, {
102
+ ...props,
103
+ display: "block",
104
+ textAlign: "start",
105
+ elementRef: this.setButtonRef,
106
+ children: summary
107
+ });
108
+ } else if (props.href) {
109
+ return _jsx("a", {
110
+ ...props,
111
+ css: this.props.styles?.toggle,
112
+ ref: this.setButtonRef,
113
+ children: summary
114
+ });
115
+ } else {
116
+ return _jsx("button", {
117
+ ...props,
118
+ type: "button",
119
+ css: this.props.styles?.toggle,
120
+ ref: this.setButtonRef,
121
+ children: summary
122
+ });
123
+ }
124
+ }
125
+ renderIcon(expanded) {
126
+ const Icon = expanded ? this.props.iconExpanded : this.props.icon;
127
+ const iconSize = this.props.size === 'large' ? 'lg' : 'md';
128
+ const iconColor = this.props.variant === 'filled' ? 'actionSecondaryBaseColor' : 'baseColor';
129
+ return this.props.children && Icon ? _jsx("span", {
130
+ css: this.props.styles?.icon,
131
+ children: _jsx(Icon, {
132
+ size: iconSize,
133
+ color: iconColor
134
+ })
135
+ }) : null;
136
+ }
137
+ renderDetails(expanded, detailsProps) {
138
+ if (!this.props.children) return null;
139
+ const expandedStyles = expanded ? {
140
+ display: 'block'
141
+ } : {
142
+ display: 'none'
143
+ };
144
+ return _jsx("div", {
145
+ ...detailsProps,
146
+ css: [this.props.styles?.details, expandedStyles],
147
+ children: expanded && this.renderContent()
148
+ });
149
+ }
150
+ renderContent() {
151
+ return _jsx("div", {
152
+ css: this.props.styles?.content,
153
+ children: this.props.children
154
+ });
155
+ }
156
+ handleToggle = (event, expanded) => {
157
+ if (typeof this.props.onToggle === 'function') {
158
+ this.props.onToggle(event, expanded);
159
+ }
160
+ };
161
+ render() {
162
+ return _jsx(Expandable, {
163
+ ...pickProps(this.props, Expandable.allowedProps),
164
+ onToggle: this.handleToggle,
165
+ children: ({
166
+ expanded,
167
+ getToggleProps,
168
+ getDetailsProps
169
+ }) => {
170
+ return _jsxs("div", {
171
+ css: this.props.styles?.toggleDetails,
172
+ ref: this.ref,
173
+ "data-cid": "ToggleDetails",
174
+ children: [this.renderToggle(getToggleProps(), expanded), this.renderDetails(expanded, getDetailsProps())]
175
+ });
176
+ }
177
+ });
178
+ }
179
+ }) || _class);
180
+ export default ToggleDetails;
181
+ export { ToggleDetails };
@@ -0,0 +1,26 @@
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 allowedProps = ['variant', 'summary', 'expanded', 'defaultExpanded', 'onToggle', 'icon', 'iconExpanded', 'iconPosition', 'fluidWidth', 'children', 'size'];
26
+ export { allowedProps };
@@ -0,0 +1,188 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { keyframes } from '@instructure/emotion';
26
+ const contentAnimation = keyframes`
27
+ to {
28
+ opacity: 1;
29
+ }`;
30
+
31
+ /**
32
+ * ---
33
+ * private: true
34
+ * ---
35
+ * Generates the style object from the theme and provided additional information
36
+ * @param {Object} componentTheme The theme variable object.
37
+ * @param {Object} props the props of the component, the style is applied to
38
+ * @param {Object} sharedTokens the shared tokens of the component
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, sharedTokens, _state) => {
43
+ const {
44
+ fluidWidth,
45
+ iconPosition,
46
+ size,
47
+ variant
48
+ } = props;
49
+ const positionIconAtEnd = iconPosition === 'end' && (variant === 'filled' || fluidWidth);
50
+ const fluidWidthStyles = fluidWidth ? {
51
+ display: 'block',
52
+ width: '100%'
53
+ } : {};
54
+ const iconPositionStyles = {
55
+ start: {
56
+ marginInlineEnd: componentTheme.iconMargin,
57
+ marginInlineStart: 0
58
+ },
59
+ end: {
60
+ marginInlineStart: componentTheme.iconMargin,
61
+ marginInlineEnd: 0
62
+ }
63
+ };
64
+ const fontSizeStyles = {
65
+ small: {
66
+ fontSize: componentTheme.fontSizeSmall
67
+ },
68
+ medium: {
69
+ fontSize: componentTheme.fontSizeMedium
70
+ },
71
+ large: {
72
+ fontSize: componentTheme.fontSizeLarge
73
+ }
74
+ };
75
+ const indentDetailsStyles = iconPosition === 'start' && !fluidWidth ? {
76
+ small: {
77
+ paddingInlineStart: `calc(${componentTheme.contentPaddingSmall} + ${componentTheme.togglePadding})`,
78
+ paddingInlineEnd: '0'
79
+ },
80
+ medium: {
81
+ paddingInlineStart: `calc(${componentTheme.contentPaddingMedium} + ${componentTheme.togglePadding})`,
82
+ paddingInlineEnd: '0'
83
+ },
84
+ large: {
85
+ paddingInlineStart: `calc(${componentTheme.contentPaddingLarge} + ${componentTheme.togglePadding})`,
86
+ paddingInlineEnd: '0'
87
+ }
88
+ } : {
89
+ small: {},
90
+ medium: {},
91
+ large: {}
92
+ };
93
+ return {
94
+ toggleDetails: {
95
+ label: 'toggleDetails',
96
+ fontFamily: componentTheme.fontFamily,
97
+ fontWeight: componentTheme.fontWeight
98
+ },
99
+ summary: {
100
+ label: 'toggleDetails__summary',
101
+ position: 'relative',
102
+ display: 'flex',
103
+ alignItems: 'center',
104
+ boxSizing: 'border-box',
105
+ textAlign: 'start'
106
+ },
107
+ summaryText: {
108
+ label: 'toggleDetails__summaryText',
109
+ minWidth: '0.0625rem',
110
+ flexGrow: 1,
111
+ ...(positionIconAtEnd ? {
112
+ flex: 1
113
+ } : {})
114
+ },
115
+ toggle: {
116
+ label: 'toggleDetails__toggle',
117
+ fontFamily: componentTheme.fontFamily,
118
+ lineHeight: componentTheme.lineHeight,
119
+ appearance: 'none',
120
+ cursor: 'pointer',
121
+ userSelect: 'none',
122
+ touchAction: 'manipulation',
123
+ position: 'relative',
124
+ overflow: 'visible',
125
+ boxSizing: 'border-box',
126
+ padding: '0',
127
+ margin: '0',
128
+ outline: 'none',
129
+ border: 'none',
130
+ background: 'transparent',
131
+ color: componentTheme.textColor,
132
+ '&::-moz-focus-inner': {
133
+ padding: '0',
134
+ margin: '0'
135
+ },
136
+ '&::before': {
137
+ content: '""',
138
+ position: 'absolute',
139
+ top: '-0.375rem',
140
+ left: '-0.375rem',
141
+ right: '-0.375rem',
142
+ bottom: '-0.375rem',
143
+ border: `${componentTheme.toggleBorderWidth} ${componentTheme.toggleBorderStyle} ${sharedTokens.focusOutline.infoColor}`,
144
+ borderRadius: `calc(${componentTheme.toggleBorderRadius} * 1.5)`,
145
+ opacity: 0,
146
+ pointerEvents: 'none'
147
+ },
148
+ '&:focus': {
149
+ '&::before': {
150
+ opacity: 1
151
+ }
152
+ },
153
+ '&:focus, &:hover, &:active': {
154
+ textDecoration: 'none',
155
+ color: componentTheme.textColor
156
+ },
157
+ textDecoration: 'none',
158
+ ...fluidWidthStyles,
159
+ ...fontSizeStyles[size]
160
+ },
161
+ icon: {
162
+ label: 'toggleDetails__icon',
163
+ display: 'flex',
164
+ alignItems: 'center',
165
+ '& > svg': {
166
+ display: 'block' /* fix vertical alignment of icon */
167
+ },
168
+ ...iconPositionStyles[iconPosition]
169
+ },
170
+ details: {
171
+ label: 'toggleDetails__details',
172
+ boxSizing: 'border-box',
173
+ paddingTop: componentTheme.togglePadding,
174
+ color: componentTheme.textColor,
175
+ lineHeight: componentTheme.lineHeight,
176
+ ...fontSizeStyles[size],
177
+ ...indentDetailsStyles[size]
178
+ },
179
+ content: {
180
+ label: 'toggleDetails__content',
181
+ opacity: 0.01,
182
+ animationName: contentAnimation,
183
+ animationFillMode: 'forwards',
184
+ animationDuration: '.3s'
185
+ }
186
+ };
187
+ };
188
+ export default generateStyle;
@@ -0,0 +1,172 @@
1
+ var _dec, _class;
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 { Component } from 'react';
27
+ import { omitProps, pickProps, getElementType, callRenderProp } from '@instructure/ui-react-utils';
28
+ import { IconButton } from '@instructure/ui-buttons/v11_6';
29
+ import { Transition } from '@instructure/ui-motion';
30
+ import { Expandable } from '@instructure/ui-expandable';
31
+ import { isActiveElement } from '@instructure/ui-dom-utils';
32
+ import { Flex } from '@instructure/ui-flex/v11_6';
33
+ import { View } from '@instructure/ui-view/v11_6';
34
+ import { IconArrowOpenEndSolid, IconArrowOpenDownSolid } from '@instructure/ui-icons';
35
+ import { allowedProps } from './props.js';
36
+ import { withStyle } from '@instructure/emotion';
37
+ import generateStyle from './styles.js';
38
+ import generateComponentTheme from './theme.js';
39
+
40
+ /**
41
+ ---
42
+ category: components
43
+ ---
44
+ **/
45
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
46
+ let ToggleGroup = (_dec = withStyle(generateStyle, generateComponentTheme), _dec(_class = class ToggleGroup extends Component {
47
+ static displayName = 'ToggleGroup';
48
+ static componentId = 'ToggleGroup';
49
+ static allowedProps = allowedProps;
50
+ static defaultProps = {
51
+ size: 'medium',
52
+ icon: IconArrowOpenEndSolid,
53
+ iconExpanded: IconArrowOpenDownSolid,
54
+ defaultExpanded: false,
55
+ transition: true,
56
+ as: 'span',
57
+ border: true
58
+ };
59
+ ref = null;
60
+ _button = null;
61
+ _shouldTransition = false;
62
+ handleRef = el => {
63
+ const {
64
+ elementRef
65
+ } = this.props;
66
+ this.ref = el;
67
+ if (typeof elementRef === 'function') {
68
+ elementRef(el);
69
+ }
70
+ };
71
+ handleButtonRef = el => {
72
+ this._button = el;
73
+ };
74
+ get focused() {
75
+ return isActiveElement(this._button);
76
+ }
77
+ focus() {
78
+ this._button?.focus();
79
+ }
80
+ componentDidMount() {
81
+ this._shouldTransition = true;
82
+ }
83
+ componentDidUpdate() {
84
+ this.props.makeStyles?.(this.state);
85
+ }
86
+ renderIcon(expanded) {
87
+ const Icon = expanded ? this.props.iconExpanded : this.props.icon;
88
+ return Icon ? callRenderProp(Icon) : null;
89
+ }
90
+ renderToggle(toggleProps, expanded) {
91
+ const {
92
+ toggleLabel,
93
+ size
94
+ } = this.props;
95
+ let label;
96
+ if (typeof toggleLabel === 'function') {
97
+ label = toggleLabel(expanded);
98
+ } else {
99
+ label = toggleLabel;
100
+ }
101
+ const props = {
102
+ ...toggleProps
103
+ };
104
+ return _jsx(IconButton, {
105
+ ...props,
106
+ withBackground: false,
107
+ withBorder: false,
108
+ size: size === 'large' ? 'medium' : 'small',
109
+ elementRef: this.handleButtonRef,
110
+ screenReaderLabel: label,
111
+ children: this.renderIcon(expanded)
112
+ });
113
+ }
114
+ renderDetails(detailsProps) {
115
+ const {
116
+ styles
117
+ } = this.props;
118
+ return _jsx(View, {
119
+ ...detailsProps,
120
+ display: "block",
121
+ borderWidth: "small none none none",
122
+ borderColor: styles?.borderColor,
123
+ children: this.props.transition && this._shouldTransition ? _jsx(Transition, {
124
+ transitionOnMount: true,
125
+ in: true,
126
+ type: "fade",
127
+ children: this.props.children
128
+ }) : this.props.children
129
+ });
130
+ }
131
+ render() {
132
+ const Element = getElementType(ToggleGroup, this.props);
133
+ const {
134
+ styles
135
+ } = this.props;
136
+ return _jsx(Expandable, {
137
+ ...pickProps(this.props, Expandable.allowedProps),
138
+ children: ({
139
+ expanded,
140
+ getToggleProps,
141
+ getDetailsProps
142
+ }) => {
143
+ return _jsxs(View, {
144
+ ...omitProps(this.props, ToggleGroup.allowedProps),
145
+ borderWidth: this.props.border ? 'small' : 'none',
146
+ as: Element,
147
+ elementRef: this.handleRef,
148
+ display: "block",
149
+ borderRadius: "medium",
150
+ background: "primary",
151
+ borderColor: styles?.borderColor,
152
+ "data-cid": "ToggleGroup",
153
+ children: [_jsxs(Flex, {
154
+ padding: this.props.size === 'small' ? 'x-small' : 'small small small x-small',
155
+ children: [_jsx(Flex.Item, {
156
+ children: this.renderToggle(getToggleProps(), expanded)
157
+ }), _jsx(Flex.Item, {
158
+ shouldGrow: true,
159
+ shouldShrink: true,
160
+ padding: "0 0 0 x-small",
161
+ children: this.props.summary
162
+ })]
163
+ }), expanded ? this.renderDetails(getDetailsProps()) : _jsx("span", {
164
+ ...getDetailsProps()
165
+ })]
166
+ });
167
+ }
168
+ });
169
+ }
170
+ }) || _class);
171
+ export default ToggleGroup;
172
+ export { ToggleGroup };
@@ -0,0 +1,26 @@
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 allowedProps = ['children', 'summary', 'toggleLabel', 'as', 'elementRef', 'size', 'expanded', 'defaultExpanded', 'onToggle', 'icon', 'iconExpanded', 'transition', 'border'];
26
+ export { allowedProps };
@@ -0,0 +1,40 @@
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
+ * ---
27
+ * private: true
28
+ * ---
29
+ * Generates the style object from the theme and provided additional information
30
+ * @param {Object} componentTheme The theme variable object.
31
+ * @param {Object} props the props of the component, the style is applied to
32
+ * @param {Object} state the state of the component, the style is applied to
33
+ * @return {Object} The final style object, which will be used in the component
34
+ */
35
+ const generateStyle = (componentTheme, _props) => {
36
+ return {
37
+ borderColor: componentTheme.borderColor
38
+ };
39
+ };
40
+ export default generateStyle;
@@ -0,0 +1,41 @@
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
+ const {
32
+ colors
33
+ } = theme;
34
+ const componentVariables = {
35
+ borderColor: colors?.contrasts?.grey3045
36
+ };
37
+ return {
38
+ ...componentVariables
39
+ };
40
+ };
41
+ export default generateComponentTheme;