@instructure/ui-buttons 11.6.0 → 11.6.1-snapshot-129

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/CHANGELOG.md +57 -323
  2. package/es/BaseButton/{index.js → v1/index.js} +2 -2
  3. package/es/BaseButton/v2/index.js +304 -0
  4. package/es/BaseButton/v2/props.js +26 -0
  5. package/es/BaseButton/v2/styles.js +578 -0
  6. package/es/Button/{index.js → v1/index.js} +2 -2
  7. package/es/{CondensedButton → Button/v1}/theme.js +1 -1
  8. package/es/Button/v2/index.js +121 -0
  9. package/es/Button/v2/props.js +26 -0
  10. package/es/CloseButton/{index.js → v1/index.js} +2 -2
  11. package/es/CloseButton/v2/index.js +130 -0
  12. package/es/CloseButton/v2/props.js +26 -0
  13. package/es/CloseButton/v2/styles.js +68 -0
  14. package/es/CondensedButton/{index.js → v1/index.js} +2 -2
  15. package/es/{Button → CondensedButton/v1}/theme.js +1 -1
  16. package/es/CondensedButton/v2/index.js +111 -0
  17. package/es/CondensedButton/v2/props.js +26 -0
  18. package/es/IconButton/{index.js → v1/index.js} +2 -2
  19. package/es/IconButton/{theme.js → v1/theme.js} +1 -1
  20. package/es/IconButton/v2/index.js +121 -0
  21. package/es/IconButton/v2/props.js +26 -0
  22. package/es/ToggleButton/{index.js → v1/index.js} +2 -2
  23. package/es/ToggleButton/v2/index.js +121 -0
  24. package/es/ToggleButton/v2/props.js +26 -0
  25. package/es/exports/a.js +29 -0
  26. package/es/exports/b.js +29 -0
  27. package/lib/BaseButton/{index.js → v1/index.js} +3 -3
  28. package/lib/BaseButton/v2/index.js +311 -0
  29. package/lib/BaseButton/v2/props.js +31 -0
  30. package/lib/BaseButton/v2/styles.js +584 -0
  31. package/lib/Button/v1/index.js +128 -0
  32. package/lib/Button/{theme.js → v1/theme.js} +1 -1
  33. package/lib/Button/{index.js → v2/index.js} +3 -4
  34. package/lib/Button/v2/props.js +31 -0
  35. package/lib/CloseButton/{index.js → v1/index.js} +4 -4
  36. package/lib/CloseButton/v2/index.js +136 -0
  37. package/lib/CloseButton/v2/props.js +31 -0
  38. package/lib/CloseButton/v2/styles.js +74 -0
  39. package/lib/CondensedButton/{index.js → v1/index.js} +3 -3
  40. package/lib/CondensedButton/{theme.js → v1/theme.js} +1 -1
  41. package/lib/CondensedButton/v2/index.js +116 -0
  42. package/lib/CondensedButton/v2/props.js +31 -0
  43. package/lib/IconButton/{index.js → v1/index.js} +3 -3
  44. package/lib/IconButton/{theme.js → v1/theme.js} +1 -1
  45. package/lib/IconButton/v2/index.js +126 -0
  46. package/lib/IconButton/v2/props.js +31 -0
  47. package/lib/ToggleButton/{index.js → v1/index.js} +4 -4
  48. package/lib/ToggleButton/v2/index.js +127 -0
  49. package/lib/ToggleButton/v2/props.js +31 -0
  50. package/lib/{index.js → exports/a.js} +12 -12
  51. package/lib/exports/b.js +47 -0
  52. package/package.json +46 -24
  53. package/src/BaseButton/{index.tsx → v1/index.tsx} +3 -3
  54. package/src/BaseButton/{props.ts → v1/props.ts} +1 -1
  55. package/src/BaseButton/v2/README.md +15 -0
  56. package/src/BaseButton/v2/index.tsx +343 -0
  57. package/src/BaseButton/v2/props.ts +226 -0
  58. package/src/BaseButton/v2/styles.ts +640 -0
  59. package/src/Button/{index.tsx → v1/index.tsx} +2 -2
  60. package/src/Button/{props.ts → v1/props.ts} +1 -1
  61. package/src/{CondensedButton → Button/v1}/theme.ts +1 -1
  62. package/src/Button/v2/README.md +338 -0
  63. package/src/Button/v2/index.tsx +137 -0
  64. package/src/Button/v2/props.ts +159 -0
  65. package/src/CloseButton/{index.tsx → v1/index.tsx} +2 -2
  66. package/src/CloseButton/{props.ts → v1/props.ts} +1 -1
  67. package/src/CloseButton/v2/README.md +70 -0
  68. package/src/CloseButton/v2/index.tsx +142 -0
  69. package/src/CloseButton/v2/props.ts +148 -0
  70. package/src/CloseButton/v2/styles.ts +81 -0
  71. package/src/CondensedButton/{index.tsx → v1/index.tsx} +2 -2
  72. package/src/CondensedButton/{props.ts → v1/props.ts} +1 -1
  73. package/src/{Button → CondensedButton/v1}/theme.ts +1 -1
  74. package/src/CondensedButton/v2/README.md +75 -0
  75. package/src/CondensedButton/v2/index.tsx +129 -0
  76. package/src/CondensedButton/v2/props.ts +134 -0
  77. package/src/IconButton/{index.tsx → v1/index.tsx} +2 -2
  78. package/src/IconButton/{props.ts → v1/props.ts} +1 -1
  79. package/src/IconButton/{theme.ts → v1/theme.ts} +1 -1
  80. package/src/IconButton/v2/README.md +86 -0
  81. package/src/IconButton/v2/index.tsx +138 -0
  82. package/src/IconButton/v2/props.ts +166 -0
  83. package/src/ToggleButton/{index.tsx → v1/index.tsx} +2 -2
  84. package/src/ToggleButton/{props.ts → v1/props.ts} +1 -1
  85. package/src/ToggleButton/v2/README.md +85 -0
  86. package/src/ToggleButton/v2/index.tsx +133 -0
  87. package/src/ToggleButton/v2/props.ts +143 -0
  88. package/src/exports/a.ts +40 -0
  89. package/src/exports/b.ts +40 -0
  90. package/tsconfig.build.tsbuildinfo +1 -1
  91. package/types/BaseButton/{index.d.ts → v1/index.d.ts} +1 -1
  92. package/types/BaseButton/v1/index.d.ts.map +1 -0
  93. package/types/BaseButton/{props.d.ts → v1/props.d.ts} +1 -1
  94. package/types/BaseButton/v1/props.d.ts.map +1 -0
  95. package/types/BaseButton/v1/styles.d.ts.map +1 -0
  96. package/types/BaseButton/v1/theme.d.ts.map +1 -0
  97. package/types/BaseButton/v2/index.d.ts +48 -0
  98. package/types/BaseButton/v2/index.d.ts.map +1 -0
  99. package/types/BaseButton/v2/props.d.ts +118 -0
  100. package/types/BaseButton/v2/props.d.ts.map +1 -0
  101. package/types/BaseButton/v2/styles.d.ts +5 -0
  102. package/types/BaseButton/v2/styles.d.ts.map +1 -0
  103. package/types/Button/{index.d.ts → v1/index.d.ts} +2 -2
  104. package/types/Button/v1/index.d.ts.map +1 -0
  105. package/types/Button/{props.d.ts → v1/props.d.ts} +1 -1
  106. package/types/Button/v1/props.d.ts.map +1 -0
  107. package/types/Button/v1/theme.d.ts +2 -0
  108. package/types/Button/v1/theme.d.ts.map +1 -0
  109. package/types/Button/v2/index.d.ts +51 -0
  110. package/types/Button/v2/index.d.ts.map +1 -0
  111. package/types/Button/v2/props.d.ts +82 -0
  112. package/types/Button/v2/props.d.ts.map +1 -0
  113. package/types/CloseButton/{index.d.ts → v1/index.d.ts} +1 -1
  114. package/types/CloseButton/v1/index.d.ts.map +1 -0
  115. package/types/CloseButton/{props.d.ts → v1/props.d.ts} +1 -1
  116. package/types/CloseButton/v1/props.d.ts.map +1 -0
  117. package/types/CloseButton/v1/styles.d.ts.map +1 -0
  118. package/types/CloseButton/v1/theme.d.ts.map +1 -0
  119. package/types/CloseButton/v2/index.d.ts +46 -0
  120. package/types/CloseButton/v2/index.d.ts.map +1 -0
  121. package/types/CloseButton/v2/props.d.ts +77 -0
  122. package/types/CloseButton/v2/props.d.ts.map +1 -0
  123. package/types/CloseButton/v2/styles.d.ts +15 -0
  124. package/types/CloseButton/v2/styles.d.ts.map +1 -0
  125. package/types/CondensedButton/{index.d.ts → v1/index.d.ts} +2 -2
  126. package/types/CondensedButton/v1/index.d.ts.map +1 -0
  127. package/types/CondensedButton/{props.d.ts → v1/props.d.ts} +1 -1
  128. package/types/CondensedButton/v1/props.d.ts.map +1 -0
  129. package/types/CondensedButton/v1/theme.d.ts +2 -0
  130. package/types/CondensedButton/v1/theme.d.ts.map +1 -0
  131. package/types/CondensedButton/v2/index.d.ts +45 -0
  132. package/types/CondensedButton/v2/index.d.ts.map +1 -0
  133. package/types/CondensedButton/v2/props.d.ts +69 -0
  134. package/types/CondensedButton/v2/props.d.ts.map +1 -0
  135. package/types/IconButton/{index.d.ts → v1/index.d.ts} +2 -2
  136. package/types/IconButton/v1/index.d.ts.map +1 -0
  137. package/types/IconButton/{props.d.ts → v1/props.d.ts} +1 -1
  138. package/types/IconButton/v1/props.d.ts.map +1 -0
  139. package/types/IconButton/v1/theme.d.ts +2 -0
  140. package/types/IconButton/v1/theme.d.ts.map +1 -0
  141. package/types/IconButton/v2/index.d.ts +51 -0
  142. package/types/IconButton/v2/index.d.ts.map +1 -0
  143. package/types/IconButton/v2/props.d.ts +85 -0
  144. package/types/IconButton/v2/props.d.ts.map +1 -0
  145. package/types/ToggleButton/{index.d.ts → v1/index.d.ts} +1 -1
  146. package/types/ToggleButton/v1/index.d.ts.map +1 -0
  147. package/types/ToggleButton/{props.d.ts → v1/props.d.ts} +1 -1
  148. package/types/ToggleButton/v1/props.d.ts.map +1 -0
  149. package/types/ToggleButton/v2/index.d.ts +43 -0
  150. package/types/ToggleButton/v2/index.d.ts.map +1 -0
  151. package/types/ToggleButton/v2/props.d.ts +75 -0
  152. package/types/ToggleButton/v2/props.d.ts.map +1 -0
  153. package/types/exports/a.d.ts +13 -0
  154. package/types/exports/a.d.ts.map +1 -0
  155. package/types/exports/b.d.ts +13 -0
  156. package/types/exports/b.d.ts.map +1 -0
  157. package/es/index.js +0 -29
  158. package/src/index.ts +0 -37
  159. package/types/BaseButton/index.d.ts.map +0 -1
  160. package/types/BaseButton/props.d.ts.map +0 -1
  161. package/types/BaseButton/styles.d.ts.map +0 -1
  162. package/types/BaseButton/theme.d.ts.map +0 -1
  163. package/types/Button/index.d.ts.map +0 -1
  164. package/types/Button/props.d.ts.map +0 -1
  165. package/types/Button/theme.d.ts +0 -2
  166. package/types/Button/theme.d.ts.map +0 -1
  167. package/types/CloseButton/index.d.ts.map +0 -1
  168. package/types/CloseButton/props.d.ts.map +0 -1
  169. package/types/CloseButton/styles.d.ts.map +0 -1
  170. package/types/CloseButton/theme.d.ts.map +0 -1
  171. package/types/CondensedButton/index.d.ts.map +0 -1
  172. package/types/CondensedButton/props.d.ts.map +0 -1
  173. package/types/CondensedButton/theme.d.ts +0 -2
  174. package/types/CondensedButton/theme.d.ts.map +0 -1
  175. package/types/IconButton/index.d.ts.map +0 -1
  176. package/types/IconButton/props.d.ts.map +0 -1
  177. package/types/IconButton/theme.d.ts +0 -2
  178. package/types/IconButton/theme.d.ts.map +0 -1
  179. package/types/ToggleButton/index.d.ts.map +0 -1
  180. package/types/ToggleButton/props.d.ts.map +0 -1
  181. package/types/index.d.ts +0 -13
  182. package/types/index.d.ts.map +0 -1
  183. /package/es/BaseButton/{props.js → v1/props.js} +0 -0
  184. /package/es/BaseButton/{styles.js → v1/styles.js} +0 -0
  185. /package/es/BaseButton/{theme.js → v1/theme.js} +0 -0
  186. /package/es/Button/{props.js → v1/props.js} +0 -0
  187. /package/es/CloseButton/{props.js → v1/props.js} +0 -0
  188. /package/es/CloseButton/{styles.js → v1/styles.js} +0 -0
  189. /package/es/CloseButton/{theme.js → v1/theme.js} +0 -0
  190. /package/es/CondensedButton/{props.js → v1/props.js} +0 -0
  191. /package/es/IconButton/{props.js → v1/props.js} +0 -0
  192. /package/es/ToggleButton/{props.js → v1/props.js} +0 -0
  193. /package/lib/BaseButton/{props.js → v1/props.js} +0 -0
  194. /package/lib/BaseButton/{styles.js → v1/styles.js} +0 -0
  195. /package/lib/BaseButton/{theme.js → v1/theme.js} +0 -0
  196. /package/lib/Button/{props.js → v1/props.js} +0 -0
  197. /package/lib/CloseButton/{props.js → v1/props.js} +0 -0
  198. /package/lib/CloseButton/{styles.js → v1/styles.js} +0 -0
  199. /package/lib/CloseButton/{theme.js → v1/theme.js} +0 -0
  200. /package/lib/CondensedButton/{props.js → v1/props.js} +0 -0
  201. /package/lib/IconButton/{props.js → v1/props.js} +0 -0
  202. /package/lib/ToggleButton/{props.js → v1/props.js} +0 -0
  203. /package/src/BaseButton/{README.md → v1/README.md} +0 -0
  204. /package/src/BaseButton/{styles.ts → v1/styles.ts} +0 -0
  205. /package/src/BaseButton/{theme.ts → v1/theme.ts} +0 -0
  206. /package/src/Button/{README.md → v1/README.md} +0 -0
  207. /package/src/CloseButton/{README.md → v1/README.md} +0 -0
  208. /package/src/CloseButton/{styles.ts → v1/styles.ts} +0 -0
  209. /package/src/CloseButton/{theme.ts → v1/theme.ts} +0 -0
  210. /package/src/CondensedButton/{README.md → v1/README.md} +0 -0
  211. /package/src/IconButton/{README.md → v1/README.md} +0 -0
  212. /package/src/ToggleButton/{README.md → v1/README.md} +0 -0
  213. /package/types/BaseButton/{styles.d.ts → v1/styles.d.ts} +0 -0
  214. /package/types/BaseButton/{theme.d.ts → v1/theme.d.ts} +0 -0
  215. /package/types/CloseButton/{styles.d.ts → v1/styles.d.ts} +0 -0
  216. /package/types/CloseButton/{theme.d.ts → v1/theme.d.ts} +0 -0
@@ -0,0 +1,70 @@
1
+ ---
2
+ describes: CloseButton
3
+ ---
4
+
5
+ Some design patterns require a `CloseButton` to be placed in the start or end position. This is a helper component that gives you the close icon out of the box and facilitates placement.
6
+
7
+ The `placement` prop designates the `CloseButton` placement within the parent container. Note that in order to apply an `offset`, `placement` should be set to `start` or `end`. Also make sure that the container has a `position` css style applied other than `static`. In the following example we use [View](View) as the container and set the `position` to `relative`.
8
+
9
+ ```js
10
+ ---
11
+ type: example
12
+ ---
13
+ <View display="block" position="relative" height="5rem" background="primary" shadow="resting">
14
+ <CloseButton placement="end" offset="small" screenReaderLabel="Close" />
15
+ </View>
16
+ ```
17
+
18
+ If you need the `CloseButton` to work in a layout with other elements vs. absolutely positioning it, you can omit the `placement` prop or set it to `static`. You can then use another tool such as [Flex](Flex) to handle the layout.
19
+
20
+ ```js
21
+ ---
22
+ type: example
23
+ ---
24
+ <View display="block" position="relative" background="primary" shadow="resting">
25
+ <Flex height="6rem" justifyItems="space-between" alignItems="center" padding="medium">
26
+ <Flex.Item shouldShrink shouldGrow>
27
+ <Heading level="h2">Some Heading Text</Heading>
28
+ </Flex.Item>
29
+ <Flex.Item padding="none none none medium">
30
+ <CloseButton size="medium" screenReaderLabel="Close" />
31
+ </Flex.Item>
32
+ </Flex>
33
+ </View>
34
+ ```
35
+
36
+ If you need even more customization, note that you can always compose this component using the [IconButton](IconButton) directly. Supply the `renderIcon` prop with [XInstUIIcon](icons) and set the `withBorder` and `withBackground` props to `false`.
37
+
38
+ ```js
39
+ ---
40
+ type: example
41
+ ---
42
+ <View display="block" position="relative" height="5rem" background="primary" shadow="resting">
43
+ <Flex justifyItems="end">
44
+ <Flex.Item>
45
+ <IconButton
46
+ screenReaderLabel="Close"
47
+ renderIcon={XInstUIIcon}
48
+ size="small"
49
+ withBackground={false}
50
+ withBorder={false}
51
+ margin="small"
52
+ />
53
+ </Flex.Item>
54
+ </Flex>
55
+ </View>
56
+ ```
57
+
58
+ ### Guidelines
59
+
60
+ ```js
61
+ ---
62
+ type: embed
63
+ ---
64
+ <Guidelines>
65
+ <Figure recommendation="a11y" title="Accessibility">
66
+ <Figure.Item>Set the <code>color</code> prop to <code>primary</code> when a CloseButton appears on a dark background to ensure adequate contrast</Figure.Item>
67
+ <Figure.Item>Ensure the CloseButton is labeled correctly using the <code>screenReaderLabel</code> prop so screen readers announce what action will be taken when selected</Figure.Item>
68
+ </Figure>
69
+ </Guidelines>
70
+ ```
@@ -0,0 +1,142 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { Component } from 'react'
26
+
27
+ import { XInstUIIcon } from '@instructure/ui-icons'
28
+ import { ScreenReaderContent } from '@instructure/ui-a11y-content'
29
+ import { getInteraction, passthroughProps } from '@instructure/ui-react-utils'
30
+
31
+ import { withStyle } from '@instructure/emotion'
32
+
33
+ import generateStyle from './styles'
34
+ import { BaseButton } from '../../BaseButton/v2'
35
+
36
+ import { allowedProps } from './props'
37
+ import type { CloseButtonProps } from './props'
38
+
39
+ /**
40
+ ---
41
+ category: components
42
+ ---
43
+ **/
44
+ @withStyle(generateStyle, 'BaseButton')
45
+ class CloseButton extends Component<CloseButtonProps> {
46
+ static readonly componentId = 'CloseButton'
47
+
48
+ static allowedProps = allowedProps
49
+ static defaultProps = {
50
+ // Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
51
+ interaction: undefined,
52
+ type: 'button',
53
+ placement: 'static',
54
+ offset: 'x-small',
55
+ size: 'small',
56
+ margin: '0',
57
+ as: 'button',
58
+ cursor: 'pointer'
59
+ }
60
+
61
+ ref: Element | null = null
62
+
63
+ handleRef = (el: Element | null) => {
64
+ const { elementRef } = this.props
65
+ if (typeof elementRef === 'function') {
66
+ elementRef(el)
67
+ }
68
+ }
69
+
70
+ componentDidMount() {
71
+ this.props.makeStyles?.()
72
+ }
73
+
74
+ componentDidUpdate() {
75
+ this.props.makeStyles?.()
76
+ }
77
+
78
+ get interaction() {
79
+ return getInteraction({ props: this.props })
80
+ }
81
+
82
+ get color() {
83
+ const { color } = this.props
84
+
85
+ return color === 'primary' ? 'secondary' : color
86
+ }
87
+
88
+ render() {
89
+ const {
90
+ screenReaderLabel,
91
+ elementRef,
92
+ size,
93
+ onClick,
94
+ margin,
95
+ placement,
96
+ offset,
97
+ type,
98
+ as,
99
+ href,
100
+ cursor,
101
+ tabIndex,
102
+ styles,
103
+ ...props
104
+ } = this.props
105
+
106
+ const themeOverride = this.props.themeOverride
107
+
108
+ return (
109
+ <span
110
+ {...passthroughProps(props)}
111
+ css={styles?.closeButton}
112
+ ref={(el) => {
113
+ this.ref = el
114
+ }}
115
+ >
116
+ <BaseButton
117
+ renderIcon={XInstUIIcon}
118
+ elementRef={this.handleRef}
119
+ interaction={this.interaction}
120
+ type={type}
121
+ {...(this.color ? { color: this.color } : {})}
122
+ size={size}
123
+ onClick={onClick}
124
+ margin={margin}
125
+ withBorder={false}
126
+ withBackground={false}
127
+ as={as}
128
+ href={href}
129
+ cursor={cursor}
130
+ tabIndex={tabIndex}
131
+ themeOverride={themeOverride}
132
+ data-cid="CloseButton"
133
+ >
134
+ <ScreenReaderContent>{screenReaderLabel}</ScreenReaderContent>
135
+ </BaseButton>
136
+ </span>
137
+ )
138
+ }
139
+ }
140
+
141
+ export default CloseButton
142
+ export { CloseButton }
@@ -0,0 +1,148 @@
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 type {
27
+ Spacing,
28
+ WithStyleProps,
29
+ ComponentStyle
30
+ } from '@instructure/emotion'
31
+ import type {
32
+ ToProp,
33
+ AsElementType,
34
+ BaseButtonTheme,
35
+ OtherHTMLAttributes
36
+ } from '@instructure/shared-types'
37
+ import type { Cursor } from '@instructure/shared-types'
38
+ import type { ViewProps } from '@instructure/ui-view/latest'
39
+
40
+ type CloseButtonOwnProps = {
41
+ /**
42
+ * An accessible label for the `CloseButton` (required)
43
+ */
44
+ screenReaderLabel: React.ReactNode
45
+
46
+ /**
47
+ * Specifies the color for the `CloseButton`.
48
+ */
49
+ color?: 'primary' | 'primary-inverse'
50
+
51
+ /**
52
+ * Specifies if interaction with the `CloseButton` is enabled, disabled, or readonly.
53
+ */
54
+ interaction?: 'enabled' | 'disabled' | 'readonly'
55
+
56
+ /**
57
+ * Provides a reference to the `CloseButton`'s underlying html element.
58
+ */
59
+ elementRef?: (element: Element | null) => void
60
+
61
+ /**
62
+ * The size of the `CloseButton`
63
+ */
64
+ size?: 'small' | 'medium' | 'large'
65
+
66
+ /**
67
+ * Callback fired when the `CloseButton` is clicked.
68
+ */
69
+ onClick?: (
70
+ event: React.KeyboardEvent<ViewProps> | React.MouseEvent<ViewProps>
71
+ ) => void
72
+
73
+ /**
74
+ * Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
75
+ * `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
76
+ * familiar CSS-like shorthand. For example: `margin="small auto large"`.
77
+ */
78
+ margin?: Spacing
79
+
80
+ /**
81
+ * Specifies the placement of the `CloseButton`
82
+ */
83
+ placement?: 'start' | 'end' | 'static'
84
+
85
+ /**
86
+ * Specifies the offset distance for the `CloseButton` with respect to both the top and start/end of the container.
87
+ * Note that for this property to have an effect, the `placement` prop must be set to either `start` or `end`. The
88
+ * offset will also be created with respect to a positioned parent. If it does not appear to be working, try setting
89
+ * the `position` of the parent container to `relative`.
90
+ */
91
+ offset?: 'none' | 'x-small' | 'small' | 'medium'
92
+
93
+ /**
94
+ * Specifies the type of the `Button`'s underlying html element.
95
+ */
96
+ type?: 'button' | 'submit' | 'reset'
97
+
98
+ /**
99
+ * The element to render as the component root, `CloseButton` by default.
100
+ */
101
+ as?: AsElementType
102
+
103
+ /**
104
+ * Specifies an href attribute for the `CloseButton`'s underlying html element.
105
+ */
106
+ href?: string
107
+
108
+ /**
109
+ * Specify a mouse cursor to use when hovering over the `CloseButton`.
110
+ */
111
+ cursor?: Cursor
112
+
113
+ /**
114
+ * Specifies the tabindex of the `CloseButton`.
115
+ *
116
+ */
117
+ tabIndex?: number
118
+ }
119
+
120
+ type PropKeys = keyof CloseButtonOwnProps
121
+
122
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
123
+
124
+ type CloseButtonProps = CloseButtonOwnProps &
125
+ WithStyleProps<BaseButtonTheme, CloseButtonStyle> &
126
+ OtherHTMLAttributes<CloseButtonOwnProps> &
127
+ ToProp
128
+
129
+ type CloseButtonStyle = ComponentStyle<'closeButton'>
130
+ const allowedProps: AllowedPropKeys = [
131
+ 'as',
132
+ 'color',
133
+ 'cursor',
134
+ 'elementRef',
135
+ 'href',
136
+ 'interaction',
137
+ 'margin',
138
+ 'offset',
139
+ 'onClick',
140
+ 'placement',
141
+ 'screenReaderLabel',
142
+ 'size',
143
+ 'tabIndex',
144
+ 'type'
145
+ ]
146
+
147
+ export type { CloseButtonProps, CloseButtonStyle }
148
+ export { allowedProps }
@@ -0,0 +1,81 @@
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 { NewComponentTypes, SharedTokens } from '@instructure/ui-themes'
26
+ import type { CloseButtonProps, CloseButtonStyle } from './props'
27
+
28
+ /**
29
+ * ---
30
+ * private: true
31
+ * ---
32
+ * Generates the style object from the theme and provided additional information
33
+ * @param {Object} _componentTheme The theme variable object.
34
+ * @param {Object} props the props of the component, the style is applied to
35
+ * @param {Object} sharedTokens the shared design tokens
36
+ * @return {Object} The final style object, which will be used in the component
37
+ */
38
+ const generateStyle = (
39
+ _componentTheme: NewComponentTypes['BaseButton'],
40
+ props: CloseButtonProps,
41
+ sharedTokens: SharedTokens
42
+ ): CloseButtonStyle => {
43
+ const { placement, offset } = props
44
+
45
+ const offsetValueMap = {
46
+ none: 0,
47
+ 'x-small': sharedTokens.spacing.general.spaceXs,
48
+ small: sharedTokens.spacing.general.spaceSm,
49
+ medium: sharedTokens.spacing.general.spaceMd,
50
+ }
51
+
52
+ const getOffsetStyle = () => {
53
+ const offsetValue = offsetValueMap[offset!]
54
+
55
+ return {
56
+ ...(offsetValue !== 0 && {
57
+ top: offsetValue
58
+ }),
59
+ insetInlineStart: placement === 'start' ? offsetValue : 'auto',
60
+ insetInlineEnd: placement === 'end' ? offsetValue : 'auto'
61
+ }
62
+ }
63
+
64
+ return {
65
+ closeButton: {
66
+ label: 'closeButton',
67
+ zIndex: 1,
68
+ display: 'inline-block',
69
+ ...(placement === 'static'
70
+ ? {
71
+ position: 'static'
72
+ }
73
+ : {
74
+ position: 'absolute',
75
+ ...getOffsetStyle()
76
+ })
77
+ }
78
+ }
79
+ }
80
+
81
+ export default generateStyle
@@ -26,10 +26,10 @@ import { Component } from 'react'
26
26
 
27
27
  import { passthroughProps } from '@instructure/ui-react-utils'
28
28
 
29
- import { withStyle } from '@instructure/emotion'
29
+ import { withStyleLegacy as withStyle } from '@instructure/emotion'
30
30
 
31
31
  import generateComponentTheme from './theme'
32
- import { BaseButton } from '../BaseButton'
32
+ import { BaseButton } from '../../BaseButton/v1'
33
33
 
34
34
  import { allowedProps } from './props'
35
35
  import type { CondensedButtonProps } from './props'
@@ -31,7 +31,7 @@ import type {
31
31
  OtherHTMLAttributes
32
32
  } from '@instructure/shared-types'
33
33
  import type { Cursor } from '@instructure/shared-types'
34
- import type { ViewProps } from '@instructure/ui-view'
34
+ import type { ViewProps } from '@instructure/ui-view/v11_6'
35
35
 
36
36
  type CondensedButtonOwnProps = {
37
37
  /**
@@ -22,4 +22,4 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- export { default } from '../BaseButton/theme'
25
+ export { default } from '../../BaseButton/v1/theme'
@@ -0,0 +1,75 @@
1
+ ---
2
+ describes: CondensedButton
3
+ ---
4
+
5
+ CondensedButton is a button component that renders without padding. It is meant specifically for tight spaces, or areas where the button padding would prevent the button content from aligning correctly with other elements.
6
+
7
+ ```js
8
+ ---
9
+ type: example
10
+ ---
11
+ <View display="block" background="primary" padding="small">
12
+ <CondensedButton>Click Me</CondensedButton>
13
+ </View>
14
+ ```
15
+
16
+ In the following example, CondensedButton is used so that the button content can align with the rest of the table cell content.
17
+
18
+ ```js
19
+ ---
20
+ type: example
21
+ ---
22
+ <Table caption='Tallest Roller Coasters'>
23
+ <Table.Head>
24
+ <Table.Row>
25
+ <Table.ColHeader id="Roller Coaster">
26
+ Roller Coaster
27
+ </Table.ColHeader>
28
+ <Table.ColHeader id="Height">
29
+ Height
30
+ </Table.ColHeader>
31
+ <Table.ColHeader id="Amusement Park">
32
+ Amusement Park
33
+ </Table.ColHeader>
34
+ </Table.Row>
35
+ </Table.Head>
36
+ <Table.Body>
37
+ <Table.Row>
38
+ <Table.Cell>
39
+ Kingda Ka<br />
40
+ <CondensedButton>View Advanced Stats</CondensedButton>
41
+ </Table.Cell>
42
+ <Table.Cell>
43
+ 456.0ft
44
+ </Table.Cell>
45
+ <Table.Cell>
46
+ Six Flags Great America
47
+ </Table.Cell>
48
+ </Table.Row>
49
+ <Table.Row>
50
+ <Table.Cell>
51
+ Top Thrill Dragster<br />
52
+ <CondensedButton>View Advanced Stats</CondensedButton>
53
+ </Table.Cell>
54
+ <Table.Cell>
55
+ 420.0ft
56
+ </Table.Cell>
57
+ <Table.Cell>
58
+ Cedar Point
59
+ </Table.Cell>
60
+ </Table.Row>
61
+ <Table.Row>
62
+ <Table.Cell>
63
+ Superman: Escape from Krypton<br />
64
+ <CondensedButton>View Advanced Stats</CondensedButton>
65
+ </Table.Cell>
66
+ <Table.Cell>
67
+ 415.0ft
68
+ </Table.Cell>
69
+ <Table.Cell>
70
+ Six Flags Magic Mountain
71
+ </Table.Cell>
72
+ </Table.Row>
73
+ </Table.Body>
74
+ </Table>
75
+ ```
@@ -0,0 +1,129 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { Component } from 'react'
26
+
27
+ import { passthroughProps } from '@instructure/ui-react-utils'
28
+
29
+ import { withStyle } from '@instructure/emotion'
30
+ import { BaseButton } from '../../BaseButton/v2'
31
+
32
+ import { allowedProps } from './props'
33
+ import type { CondensedButtonProps } from './props'
34
+
35
+ /**
36
+ ---
37
+ category: components
38
+ ---
39
+ **/
40
+ // needed for listing the available theme variables on docs page
41
+ @withStyle(null, 'BaseButton')
42
+ class CondensedButton extends Component<CondensedButtonProps> {
43
+ static readonly componentId = 'CondensedButton'
44
+
45
+ static allowedProps = allowedProps
46
+ static defaultProps = {
47
+ type: 'button',
48
+ size: 'medium',
49
+ as: 'button',
50
+ // Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
51
+ interaction: undefined,
52
+ color: 'primary',
53
+ margin: '0',
54
+ cursor: 'pointer',
55
+ display: 'inline-block'
56
+ }
57
+
58
+ _baseButton: BaseButton | null = null
59
+
60
+ ref: Element | null = null
61
+
62
+ handleRef = (el: Element | null) => {
63
+ const { elementRef } = this.props
64
+
65
+ this.ref = el
66
+
67
+ if (typeof elementRef === 'function') {
68
+ elementRef(el)
69
+ }
70
+ }
71
+
72
+ get focused() {
73
+ return this._baseButton && this._baseButton.focused
74
+ }
75
+
76
+ focus() {
77
+ this._baseButton && this._baseButton.focus()
78
+ }
79
+
80
+ render() {
81
+ const {
82
+ children,
83
+ type,
84
+ size,
85
+ elementRef,
86
+ as,
87
+ interaction,
88
+ color,
89
+ margin,
90
+ cursor,
91
+ href,
92
+ renderIcon,
93
+ display,
94
+ ...props
95
+ } = this.props
96
+
97
+ const themeOverride = this.props.themeOverride
98
+
99
+ return (
100
+ <BaseButton
101
+ {...passthroughProps(props)}
102
+ isCondensed
103
+ display={display}
104
+ withBackground={false}
105
+ withBorder={false}
106
+ type={type}
107
+ size={size}
108
+ elementRef={this.handleRef}
109
+ as={as}
110
+ interaction={interaction}
111
+ color={color}
112
+ margin={margin}
113
+ cursor={cursor}
114
+ href={href}
115
+ renderIcon={renderIcon}
116
+ themeOverride={themeOverride}
117
+ ref={(component) => {
118
+ this._baseButton = component
119
+ }}
120
+ data-cid="CondensedButton"
121
+ >
122
+ {children}
123
+ </BaseButton>
124
+ )
125
+ }
126
+ }
127
+
128
+ export default CondensedButton
129
+ export { CondensedButton }