@instructure/ui-buttons 8.13.1-snapshot.9 → 8.14.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 +4 -0
- package/es/BaseButton/index.js +64 -43
- package/es/BaseButton/props.js +2 -88
- package/es/BaseButton/theme.js +1 -1
- package/es/Button/index.js +2 -2
- package/es/Button/props.js +3 -65
- package/es/CloseButton/index.js +23 -18
- package/es/CloseButton/props.js +2 -60
- package/es/CondensedButton/index.js +2 -2
- package/es/CondensedButton/props.js +3 -48
- package/es/IconButton/index.js +2 -2
- package/es/IconButton/props.js +3 -68
- package/es/ToggleButton/index.js +4 -5
- package/es/ToggleButton/props.js +1 -58
- package/lib/BaseButton/index.js +67 -43
- package/lib/BaseButton/props.js +2 -88
- package/lib/BaseButton/theme.js +1 -1
- package/lib/Button/index.js +2 -2
- package/lib/Button/props.js +3 -65
- package/lib/CloseButton/index.js +23 -18
- package/lib/CloseButton/props.js +2 -60
- package/lib/CondensedButton/index.js +2 -2
- package/lib/CondensedButton/props.js +3 -48
- package/lib/IconButton/index.js +2 -2
- package/lib/IconButton/props.js +3 -68
- package/lib/ToggleButton/index.js +4 -5
- package/lib/ToggleButton/props.js +1 -58
- package/package.json +21 -22
- package/src/BaseButton/index.tsx +35 -27
- package/src/BaseButton/props.ts +103 -72
- package/src/BaseButton/theme.ts +1 -6
- package/src/Button/index.tsx +4 -8
- package/src/Button/props.ts +74 -48
- package/src/CloseButton/index.tsx +4 -6
- package/src/CloseButton/props.ts +67 -41
- package/src/CondensedButton/index.tsx +3 -7
- package/src/CondensedButton/props.ts +56 -34
- package/src/IconButton/index.tsx +3 -7
- package/src/IconButton/props.ts +77 -50
- package/src/ToggleButton/index.tsx +8 -15
- package/src/ToggleButton/props.ts +65 -39
- package/tsconfig.build.json +25 -2
- package/tsconfig.build.tsbuildinfo +1 -0
- package/types/BaseButton/BaseButtonLocator.d.ts +57 -56
- package/types/BaseButton/BaseButtonLocator.d.ts.map +1 -1
- package/types/BaseButton/index.d.ts +16 -15
- package/types/BaseButton/index.d.ts.map +1 -1
- package/types/BaseButton/props.d.ts +76 -5
- package/types/BaseButton/props.d.ts.map +1 -1
- package/types/BaseButton/theme.d.ts.map +1 -1
- package/types/Button/ButtonLocator.d.ts +57 -56
- package/types/Button/ButtonLocator.d.ts.map +1 -1
- package/types/Button/index.d.ts +10 -7
- package/types/Button/index.d.ts.map +1 -1
- package/types/Button/locator.d.ts +52 -52
- package/types/Button/props.d.ts +57 -3
- package/types/Button/props.d.ts.map +1 -1
- package/types/CloseButton/CloseButtonLocator.d.ts +52 -52
- package/types/CloseButton/index.d.ts +4 -3
- package/types/CloseButton/index.d.ts.map +1 -1
- package/types/CloseButton/props.d.ts +55 -5
- package/types/CloseButton/props.d.ts.map +1 -1
- package/types/CondensedButton/CondensedButtonLocator.d.ts +57 -56
- package/types/CondensedButton/CondensedButtonLocator.d.ts.map +1 -1
- package/types/CondensedButton/index.d.ts +9 -6
- package/types/CondensedButton/index.d.ts.map +1 -1
- package/types/CondensedButton/props.d.ts +44 -3
- package/types/CondensedButton/props.d.ts.map +1 -1
- package/types/IconButton/IconButtonLocator.d.ts +57 -56
- package/types/IconButton/IconButtonLocator.d.ts.map +1 -1
- package/types/IconButton/index.d.ts +11 -8
- package/types/IconButton/index.d.ts.map +1 -1
- package/types/IconButton/props.d.ts +60 -4
- package/types/IconButton/props.d.ts.map +1 -1
- package/types/ToggleButton/ToggleButtonLocator.d.ts +57 -56
- package/types/ToggleButton/ToggleButtonLocator.d.ts.map +1 -1
- package/types/ToggleButton/index.d.ts +12 -13
- package/types/ToggleButton/index.d.ts.map +1 -1
- package/types/ToggleButton/props.d.ts +52 -4
- package/types/ToggleButton/props.d.ts.map +1 -1
- package/LICENSE.md +0 -27
|
@@ -43,6 +43,7 @@ import type { CloseButtonProps } from './props'
|
|
|
43
43
|
---
|
|
44
44
|
category: components
|
|
45
45
|
---
|
|
46
|
+
@tsProps
|
|
46
47
|
**/
|
|
47
48
|
@withStyle(generateStyle, generateComponentTheme)
|
|
48
49
|
@testable()
|
|
@@ -52,9 +53,8 @@ class CloseButton extends Component<CloseButtonProps> {
|
|
|
52
53
|
static propTypes = propTypes
|
|
53
54
|
static allowedProps = allowedProps
|
|
54
55
|
static defaultProps = {
|
|
55
|
-
// @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
|
|
56
|
-
onClick: (event) => {},
|
|
57
56
|
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
57
|
+
interaction: undefined,
|
|
58
58
|
type: 'button',
|
|
59
59
|
placement: 'static',
|
|
60
60
|
offset: 'x-small',
|
|
@@ -77,13 +77,11 @@ class CloseButton extends Component<CloseButtonProps> {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
componentDidMount() {
|
|
80
|
-
|
|
81
|
-
this.props.makeStyles()
|
|
80
|
+
this.props.makeStyles?.()
|
|
82
81
|
}
|
|
83
82
|
|
|
84
83
|
componentDidUpdate() {
|
|
85
|
-
|
|
86
|
-
this.props.makeStyles()
|
|
84
|
+
this.props.makeStyles?.()
|
|
87
85
|
}
|
|
88
86
|
|
|
89
87
|
get interaction() {
|
package/src/CloseButton/props.ts
CHANGED
|
@@ -22,7 +22,9 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
+
import React from 'react'
|
|
25
26
|
import PropTypes from 'prop-types'
|
|
27
|
+
|
|
26
28
|
import { ThemeablePropTypes } from '@instructure/emotion'
|
|
27
29
|
|
|
28
30
|
import type {
|
|
@@ -31,102 +33,126 @@ import type {
|
|
|
31
33
|
ComponentStyle
|
|
32
34
|
} from '@instructure/emotion'
|
|
33
35
|
import type {
|
|
36
|
+
ToProp,
|
|
34
37
|
AsElementType,
|
|
35
38
|
CloseButtonTheme,
|
|
36
39
|
OtherHTMLAttributes,
|
|
37
40
|
PropValidators
|
|
38
41
|
} from '@instructure/shared-types'
|
|
39
42
|
import type { Cursor } from '@instructure/ui-prop-types'
|
|
43
|
+
import type { ViewProps } from '@instructure/ui-view'
|
|
40
44
|
|
|
41
45
|
type CloseButtonOwnProps = {
|
|
42
|
-
screenReaderLabel: string | React.ReactNode
|
|
43
|
-
color?: 'primary' | 'primary-inverse'
|
|
44
|
-
interaction?: 'enabled' | 'disabled' | 'readonly'
|
|
45
|
-
elementRef?: (element: Element | null) => void
|
|
46
|
-
size?: 'small' | 'medium' | 'large'
|
|
47
|
-
onClick?: (...args: any[]) => any
|
|
48
|
-
margin?: Spacing
|
|
49
|
-
placement?: 'start' | 'end' | 'static'
|
|
50
|
-
offset?: 'none' | 'x-small' | 'small' | 'medium'
|
|
51
|
-
type?: 'button' | 'submit' | 'reset'
|
|
52
|
-
as?: AsElementType
|
|
53
|
-
href?: string
|
|
54
|
-
cursor?: Cursor
|
|
55
|
-
tabIndex?: number | string
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
type PropKeys = keyof CloseButtonOwnProps
|
|
59
|
-
|
|
60
|
-
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
61
|
-
|
|
62
|
-
type CloseButtonProps = CloseButtonOwnProps &
|
|
63
|
-
WithStyleProps<CloseButtonTheme, CloseButtonStyle> &
|
|
64
|
-
OtherHTMLAttributes<CloseButtonOwnProps>
|
|
65
|
-
|
|
66
|
-
type CloseButtonStyle = ComponentStyle<'closeButton'>
|
|
67
|
-
|
|
68
|
-
const propTypes: PropValidators<PropKeys> = {
|
|
69
46
|
/**
|
|
70
47
|
* An accessible label for the `CloseButton` (required)
|
|
71
48
|
*/
|
|
72
|
-
screenReaderLabel:
|
|
73
|
-
|
|
49
|
+
screenReaderLabel: React.ReactNode
|
|
50
|
+
|
|
74
51
|
/**
|
|
75
52
|
* Specifies the color for the `CloseButton`.
|
|
76
53
|
*/
|
|
77
|
-
color
|
|
54
|
+
color?: 'primary' | 'primary-inverse'
|
|
55
|
+
|
|
78
56
|
/**
|
|
79
57
|
* Specifies if interaction with the `CloseButton` is enabled, disabled, or readonly.
|
|
80
58
|
*/
|
|
81
|
-
interaction
|
|
59
|
+
interaction?: 'enabled' | 'disabled' | 'readonly'
|
|
60
|
+
|
|
82
61
|
/**
|
|
83
62
|
* Provides a reference to the `CloseButton`'s underlying html element.
|
|
84
63
|
*/
|
|
85
|
-
elementRef:
|
|
64
|
+
elementRef?: (element: Element | null) => void
|
|
65
|
+
|
|
86
66
|
/**
|
|
87
67
|
* The size of the `CloseButton`
|
|
88
68
|
*/
|
|
89
|
-
size
|
|
69
|
+
size?: 'small' | 'medium' | 'large'
|
|
70
|
+
|
|
90
71
|
/**
|
|
91
72
|
* Callback fired when the `CloseButton` is clicked.
|
|
92
73
|
*/
|
|
93
|
-
onClick
|
|
74
|
+
onClick?: (
|
|
75
|
+
event: React.KeyboardEvent<ViewProps> | React.MouseEvent<ViewProps>
|
|
76
|
+
) => void
|
|
77
|
+
|
|
94
78
|
/**
|
|
95
79
|
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
96
80
|
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
97
81
|
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
98
82
|
*/
|
|
99
|
-
margin
|
|
83
|
+
margin?: Spacing
|
|
84
|
+
|
|
100
85
|
/**
|
|
101
86
|
* Specifies the placement of the `CloseButton`
|
|
102
87
|
*/
|
|
103
|
-
placement
|
|
88
|
+
placement?: 'start' | 'end' | 'static'
|
|
89
|
+
|
|
104
90
|
/**
|
|
105
91
|
* Specifies the offset distance for the `CloseButton` with respect to both the top and start/end of the container.
|
|
106
92
|
* Note that for this property to have an effect, the `placement` prop must be set to either `start` or `end`. The
|
|
107
93
|
* offset will also be created with respect to a positioned parent. If it does not appear to be working, try setting
|
|
108
94
|
* the `position` of the parent container to `relative`.
|
|
109
95
|
*/
|
|
110
|
-
offset
|
|
96
|
+
offset?: 'none' | 'x-small' | 'small' | 'medium'
|
|
97
|
+
|
|
111
98
|
/**
|
|
112
99
|
* Specifies the type of the `Button`'s underlying html element.
|
|
113
100
|
*/
|
|
114
|
-
type
|
|
101
|
+
type?: 'button' | 'submit' | 'reset'
|
|
102
|
+
|
|
115
103
|
/**
|
|
116
104
|
* The element to render as the component root, `CloseButton` by default.
|
|
117
105
|
*/
|
|
118
|
-
as
|
|
106
|
+
as?: AsElementType
|
|
107
|
+
|
|
119
108
|
/**
|
|
120
109
|
* Specifies an href attribute for the `CloseButton`'s underlying html element.
|
|
121
110
|
*/
|
|
122
|
-
href
|
|
111
|
+
href?: string
|
|
112
|
+
|
|
123
113
|
/**
|
|
124
114
|
* Specify a mouse cursor to use when hovering over the `CloseButton`.
|
|
125
115
|
*/
|
|
126
|
-
cursor
|
|
116
|
+
cursor?: Cursor
|
|
117
|
+
|
|
118
|
+
// Deprecated `string` tabIndex type
|
|
119
|
+
// TODO: remove string type in v9
|
|
127
120
|
/**
|
|
128
121
|
* Specifies the tabindex of the `CloseButton`.
|
|
122
|
+
*
|
|
123
|
+
* (`string` type is __deprecated__, use `number`)
|
|
129
124
|
*/
|
|
125
|
+
tabIndex?: number | string
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
type PropKeys = keyof CloseButtonOwnProps
|
|
129
|
+
|
|
130
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
131
|
+
|
|
132
|
+
type CloseButtonProps = CloseButtonOwnProps &
|
|
133
|
+
WithStyleProps<CloseButtonTheme, CloseButtonStyle> &
|
|
134
|
+
OtherHTMLAttributes<CloseButtonOwnProps> &
|
|
135
|
+
ToProp
|
|
136
|
+
|
|
137
|
+
type CloseButtonStyle = ComponentStyle<'closeButton'>
|
|
138
|
+
|
|
139
|
+
const propTypes: PropValidators<PropKeys> = {
|
|
140
|
+
screenReaderLabel: PropTypes.oneOfType([PropTypes.string, PropTypes.node])
|
|
141
|
+
.isRequired,
|
|
142
|
+
color: PropTypes.oneOf(['primary', 'primary-inverse']),
|
|
143
|
+
interaction: PropTypes.oneOf(['enabled', 'disabled', 'readonly']),
|
|
144
|
+
elementRef: PropTypes.func,
|
|
145
|
+
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
146
|
+
onClick: PropTypes.func,
|
|
147
|
+
margin: ThemeablePropTypes.spacing,
|
|
148
|
+
placement: PropTypes.oneOf(['start', 'end', 'static']),
|
|
149
|
+
offset: PropTypes.oneOf(['none', 'x-small', 'small', 'medium']),
|
|
150
|
+
type: PropTypes.oneOf(['button', 'submit', 'reset']),
|
|
151
|
+
as: PropTypes.elementType,
|
|
152
|
+
href: PropTypes.string,
|
|
153
|
+
cursor: PropTypes.string,
|
|
154
|
+
// Deprecated `string` tabIndex type
|
|
155
|
+
// TODO: remove string type in v9
|
|
130
156
|
tabIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
131
157
|
}
|
|
132
158
|
|
|
@@ -39,6 +39,7 @@ import type { CondensedButtonProps } from './props'
|
|
|
39
39
|
---
|
|
40
40
|
category: components
|
|
41
41
|
---
|
|
42
|
+
@tsProps
|
|
42
43
|
**/
|
|
43
44
|
// needed for listing the available theme variables on docs page
|
|
44
45
|
@withStyle(null, generateComponentTheme)
|
|
@@ -49,19 +50,17 @@ class CondensedButton extends Component<CondensedButtonProps> {
|
|
|
49
50
|
static propTypes = propTypes
|
|
50
51
|
static allowedProps = allowedProps
|
|
51
52
|
static defaultProps = {
|
|
52
|
-
children: null,
|
|
53
53
|
type: 'button',
|
|
54
54
|
size: 'medium',
|
|
55
|
-
// @ts-expect-error ts-migrate(6133) FIXME: 'el' is declared but its value is never read.
|
|
56
|
-
elementRef: (el) => {},
|
|
57
55
|
as: 'button',
|
|
58
56
|
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
57
|
+
interaction: undefined,
|
|
59
58
|
color: 'primary',
|
|
60
59
|
margin: '0',
|
|
61
60
|
cursor: 'pointer'
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
_baseButton = null
|
|
63
|
+
_baseButton: BaseButton | null = null
|
|
65
64
|
|
|
66
65
|
ref: Element | null = null
|
|
67
66
|
|
|
@@ -76,12 +75,10 @@ class CondensedButton extends Component<CondensedButtonProps> {
|
|
|
76
75
|
}
|
|
77
76
|
|
|
78
77
|
get focused() {
|
|
79
|
-
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
|
80
78
|
return this._baseButton && this._baseButton.focused
|
|
81
79
|
}
|
|
82
80
|
|
|
83
81
|
focus() {
|
|
84
|
-
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
|
85
82
|
this._baseButton && this._baseButton.focus()
|
|
86
83
|
}
|
|
87
84
|
|
|
@@ -121,7 +118,6 @@ class CondensedButton extends Component<CondensedButtonProps> {
|
|
|
121
118
|
renderIcon={renderIcon}
|
|
122
119
|
themeOverride={themeOverride}
|
|
123
120
|
ref={(component) => {
|
|
124
|
-
// @ts-expect-error ts-migrate(2322) FIXME: Type 'BaseButton | null' is not assignable to type... Remove this comment to see the full error message
|
|
125
121
|
this._baseButton = component
|
|
126
122
|
}}
|
|
127
123
|
>
|
|
@@ -29,83 +29,104 @@ import { ThemeablePropTypes } from '@instructure/emotion'
|
|
|
29
29
|
|
|
30
30
|
import type { Spacing, WithStyleProps } from '@instructure/emotion'
|
|
31
31
|
import type {
|
|
32
|
+
ToProp,
|
|
32
33
|
AsElementType,
|
|
33
34
|
BaseButtonTheme,
|
|
34
35
|
OtherHTMLAttributes,
|
|
35
36
|
PropValidators
|
|
36
37
|
} from '@instructure/shared-types'
|
|
37
38
|
import type { Cursor } from '@instructure/ui-prop-types'
|
|
39
|
+
import type { ViewProps } from '@instructure/ui-view'
|
|
38
40
|
|
|
39
41
|
type CondensedButtonOwnProps = {
|
|
40
|
-
children?: React.ReactNode
|
|
41
|
-
type?: 'button' | 'submit' | 'reset'
|
|
42
|
-
size?: 'small' | 'medium' | 'large'
|
|
43
|
-
elementRef?: (element: Element | null) => void
|
|
44
|
-
as?: AsElementType
|
|
45
|
-
interaction?: 'enabled' | 'disabled' | 'readonly'
|
|
46
|
-
color?: 'primary' | 'primary-inverse'
|
|
47
|
-
margin?: Spacing
|
|
48
|
-
cursor?: Cursor
|
|
49
|
-
href?: string
|
|
50
|
-
renderIcon?: React.ReactNode | ((...args: any[]) => any)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
type PropKeys = keyof CondensedButtonOwnProps
|
|
54
|
-
|
|
55
|
-
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
56
|
-
|
|
57
|
-
type CondensedButtonProps = CondensedButtonOwnProps &
|
|
58
|
-
WithStyleProps<BaseButtonTheme, null> &
|
|
59
|
-
OtherHTMLAttributes<CondensedButtonOwnProps>
|
|
60
|
-
|
|
61
|
-
const propTypes: PropValidators<PropKeys> = {
|
|
62
42
|
/**
|
|
63
43
|
* Specifies the `CondensedButton` children.
|
|
64
44
|
*/
|
|
65
|
-
children
|
|
45
|
+
children?: React.ReactNode
|
|
46
|
+
|
|
66
47
|
/**
|
|
67
48
|
* Specifies the type of the `CondensedButton`'s underlying html element.
|
|
68
49
|
*/
|
|
69
|
-
type
|
|
50
|
+
type?: 'button' | 'submit' | 'reset'
|
|
51
|
+
|
|
70
52
|
/**
|
|
71
53
|
* The size of the `CondensedButton`
|
|
72
54
|
*/
|
|
73
|
-
size
|
|
55
|
+
size?: 'small' | 'medium' | 'large'
|
|
56
|
+
|
|
74
57
|
/**
|
|
75
58
|
* Provides a reference to the `CondensedButton`'s underlying html element.
|
|
76
59
|
*/
|
|
77
|
-
elementRef:
|
|
60
|
+
elementRef?: (element: Element | null) => void
|
|
61
|
+
|
|
78
62
|
/**
|
|
79
63
|
* The element to render as the component root, `button` by default.
|
|
80
64
|
*/
|
|
81
|
-
as
|
|
65
|
+
as?: AsElementType
|
|
66
|
+
|
|
82
67
|
/**
|
|
83
68
|
* Specifies if interaction with the `CondensedButton` is enabled, disabled, or readonly.
|
|
84
69
|
*/
|
|
85
|
-
interaction
|
|
70
|
+
interaction?: 'enabled' | 'disabled' | 'readonly'
|
|
71
|
+
|
|
86
72
|
/**
|
|
87
73
|
* Specifies the color for the `CondensedButton`.
|
|
88
74
|
*/
|
|
89
|
-
color
|
|
75
|
+
color?: 'primary' | 'primary-inverse'
|
|
76
|
+
|
|
90
77
|
/**
|
|
91
78
|
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
92
79
|
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
93
80
|
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
94
81
|
*/
|
|
95
|
-
margin
|
|
82
|
+
margin?: Spacing
|
|
83
|
+
|
|
96
84
|
/**
|
|
97
85
|
* Specify a mouse cursor to use when hovering over the button.
|
|
98
86
|
* The `pointer` cursor is used by default.
|
|
99
87
|
*/
|
|
100
|
-
cursor
|
|
88
|
+
cursor?: Cursor
|
|
89
|
+
|
|
101
90
|
/**
|
|
102
91
|
* Specifies an href attribute for the `CondensedButton`'s underlying html element.
|
|
103
92
|
*/
|
|
104
|
-
href
|
|
93
|
+
href?: string
|
|
94
|
+
|
|
105
95
|
/**
|
|
106
96
|
* An icon, or function that returns an icon.
|
|
107
97
|
*/
|
|
108
|
-
renderIcon
|
|
98
|
+
renderIcon?: React.ReactNode | (() => React.ReactNode)
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Callback fired when the `CondensedButton` is clicked.
|
|
102
|
+
*/
|
|
103
|
+
onClick?: (
|
|
104
|
+
event: React.KeyboardEvent<ViewProps> | React.MouseEvent<ViewProps>
|
|
105
|
+
) => void
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
type PropKeys = keyof CondensedButtonOwnProps
|
|
109
|
+
|
|
110
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
111
|
+
|
|
112
|
+
type CondensedButtonProps = CondensedButtonOwnProps &
|
|
113
|
+
WithStyleProps<BaseButtonTheme, null> &
|
|
114
|
+
OtherHTMLAttributes<CondensedButtonOwnProps> &
|
|
115
|
+
ToProp
|
|
116
|
+
|
|
117
|
+
const propTypes: PropValidators<PropKeys> = {
|
|
118
|
+
children: PropTypes.node,
|
|
119
|
+
type: PropTypes.oneOf(['button', 'submit', 'reset']),
|
|
120
|
+
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
121
|
+
elementRef: PropTypes.func,
|
|
122
|
+
as: PropTypes.elementType,
|
|
123
|
+
interaction: PropTypes.oneOf(['enabled', 'disabled', 'readonly']),
|
|
124
|
+
color: PropTypes.oneOf(['primary', 'primary-inverse']),
|
|
125
|
+
margin: ThemeablePropTypes.spacing,
|
|
126
|
+
cursor: PropTypes.string,
|
|
127
|
+
href: PropTypes.string,
|
|
128
|
+
renderIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
129
|
+
onClick: PropTypes.func
|
|
109
130
|
}
|
|
110
131
|
|
|
111
132
|
const allowedProps: AllowedPropKeys = [
|
|
@@ -119,7 +140,8 @@ const allowedProps: AllowedPropKeys = [
|
|
|
119
140
|
'margin',
|
|
120
141
|
'renderIcon',
|
|
121
142
|
'size',
|
|
122
|
-
'type'
|
|
143
|
+
'type',
|
|
144
|
+
'onClick'
|
|
123
145
|
]
|
|
124
146
|
|
|
125
147
|
export type { CondensedButtonProps }
|
package/src/IconButton/index.tsx
CHANGED
|
@@ -40,6 +40,7 @@ import type { IconButtonProps } from './props'
|
|
|
40
40
|
---
|
|
41
41
|
category: components
|
|
42
42
|
---
|
|
43
|
+
@tsProps
|
|
43
44
|
**/
|
|
44
45
|
|
|
45
46
|
// needed for listing the available theme variables on docs page
|
|
@@ -51,13 +52,11 @@ class IconButton extends Component<IconButtonProps> {
|
|
|
51
52
|
static propTypes = propTypes
|
|
52
53
|
static allowedProps = allowedProps
|
|
53
54
|
static defaultProps = {
|
|
54
|
-
children: null,
|
|
55
55
|
type: 'button',
|
|
56
56
|
size: 'medium',
|
|
57
|
-
// @ts-expect-error ts-migrate(6133) FIXME: 'el' is declared but its value is never read.
|
|
58
|
-
elementRef: (el) => {},
|
|
59
57
|
as: 'button',
|
|
60
58
|
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
59
|
+
interaction: undefined,
|
|
61
60
|
color: 'secondary',
|
|
62
61
|
shape: 'rectangle',
|
|
63
62
|
withBackground: true,
|
|
@@ -66,7 +65,7 @@ class IconButton extends Component<IconButtonProps> {
|
|
|
66
65
|
cursor: 'pointer'
|
|
67
66
|
}
|
|
68
67
|
|
|
69
|
-
_baseButton = null
|
|
68
|
+
_baseButton: BaseButton | null = null
|
|
70
69
|
|
|
71
70
|
ref: Element | null = null
|
|
72
71
|
|
|
@@ -81,12 +80,10 @@ class IconButton extends Component<IconButtonProps> {
|
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
get focused() {
|
|
84
|
-
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
|
85
83
|
return this._baseButton && this._baseButton.focused
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
focus() {
|
|
89
|
-
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
|
90
87
|
this._baseButton && this._baseButton.focus()
|
|
91
88
|
}
|
|
92
89
|
|
|
@@ -132,7 +129,6 @@ class IconButton extends Component<IconButtonProps> {
|
|
|
132
129
|
renderIcon={children || renderIcon}
|
|
133
130
|
themeOverride={themeOverride}
|
|
134
131
|
ref={(component) => {
|
|
135
|
-
// @ts-expect-error ts-migrate(2322) FIXME: Type 'BaseButton | null' is not assignable to type... Remove this comment to see the full error message
|
|
136
132
|
this._baseButton = component
|
|
137
133
|
}}
|
|
138
134
|
>
|
package/src/IconButton/props.ts
CHANGED
|
@@ -29,114 +29,140 @@ import { ThemeablePropTypes } from '@instructure/emotion'
|
|
|
29
29
|
|
|
30
30
|
import type { Spacing, WithStyleProps } from '@instructure/emotion'
|
|
31
31
|
import type {
|
|
32
|
+
ToProp,
|
|
32
33
|
AsElementType,
|
|
33
34
|
PropValidators,
|
|
34
35
|
BaseButtonTheme,
|
|
35
36
|
OtherHTMLAttributes
|
|
36
37
|
} from '@instructure/shared-types'
|
|
37
38
|
import type { Cursor } from '@instructure/ui-prop-types'
|
|
39
|
+
import type { ViewProps } from '@instructure/ui-view'
|
|
38
40
|
|
|
39
41
|
type IconButtonOwnProps = {
|
|
40
|
-
children?: React.ReactNode | ((...args: any[]) => React.ReactNode)
|
|
41
|
-
renderIcon?: React.ReactNode | ((...args: any[]) => any)
|
|
42
|
-
screenReaderLabel: string
|
|
43
|
-
type?: 'button' | 'submit' | 'reset'
|
|
44
|
-
size?: 'small' | 'medium' | 'large'
|
|
45
|
-
elementRef?: (element: Element | null) => void
|
|
46
|
-
as?: AsElementType
|
|
47
|
-
interaction?: 'enabled' | 'disabled' | 'readonly'
|
|
48
|
-
color?: 'primary' | 'primary-inverse' | 'secondary' | 'success' | 'danger'
|
|
49
|
-
focusColor?: 'info' | 'inverse'
|
|
50
|
-
shape?: 'rectangle' | 'circle'
|
|
51
|
-
withBackground?: boolean
|
|
52
|
-
withBorder?: boolean
|
|
53
|
-
margin?: Spacing
|
|
54
|
-
cursor?: Cursor
|
|
55
|
-
href?: string
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
type PropKeys = keyof IconButtonOwnProps
|
|
59
|
-
|
|
60
|
-
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
61
|
-
|
|
62
|
-
type IconButtonProps = IconButtonOwnProps &
|
|
63
|
-
WithStyleProps<BaseButtonTheme, null> &
|
|
64
|
-
OtherHTMLAttributes<IconButtonOwnProps>
|
|
65
|
-
|
|
66
|
-
const propTypes: PropValidators<PropKeys> = {
|
|
67
42
|
/**
|
|
68
43
|
* An icon, or function returning an icon (identical to the `renderIcon` prop).
|
|
69
44
|
*/
|
|
70
|
-
children
|
|
45
|
+
children?: React.ReactNode | (() => React.ReactNode)
|
|
46
|
+
|
|
71
47
|
/**
|
|
72
48
|
* An icon, or function that returns an icon (identical to the `children` prop).
|
|
73
49
|
*/
|
|
74
|
-
renderIcon
|
|
50
|
+
renderIcon?: React.ReactNode | (() => React.ReactNode)
|
|
51
|
+
|
|
75
52
|
/**
|
|
76
53
|
* An accessible label for the `IconButton`.
|
|
77
54
|
*/
|
|
78
|
-
screenReaderLabel:
|
|
55
|
+
screenReaderLabel: string
|
|
56
|
+
|
|
79
57
|
/**
|
|
80
58
|
* Specifies the type of the `IconButton`'s underlying html element.
|
|
81
59
|
*/
|
|
82
|
-
type
|
|
60
|
+
type?: 'button' | 'submit' | 'reset'
|
|
61
|
+
|
|
83
62
|
/**
|
|
84
63
|
* The size of the `IconButton`
|
|
85
64
|
*/
|
|
86
|
-
size
|
|
65
|
+
size?: 'small' | 'medium' | 'large'
|
|
66
|
+
|
|
87
67
|
/**
|
|
88
68
|
* Provides a reference to the `IconButton`'s underlying html element.
|
|
89
69
|
*/
|
|
90
|
-
elementRef:
|
|
70
|
+
elementRef?: (element: Element | null) => void
|
|
71
|
+
|
|
91
72
|
/**
|
|
92
73
|
* The element to render as the component root, `button` by default.
|
|
93
74
|
*/
|
|
94
|
-
as
|
|
75
|
+
as?: AsElementType
|
|
76
|
+
|
|
95
77
|
/**
|
|
96
78
|
* Specifies if interaction with the `IconButton` is enabled, disabled, or readonly.
|
|
97
79
|
*/
|
|
98
|
-
interaction
|
|
80
|
+
interaction?: 'enabled' | 'disabled' | 'readonly'
|
|
81
|
+
|
|
99
82
|
/**
|
|
100
83
|
* Specifies the color for the `IconButton`.
|
|
101
84
|
*/
|
|
102
|
-
color
|
|
103
|
-
|
|
104
|
-
'primary-inverse',
|
|
105
|
-
'secondary',
|
|
106
|
-
'success',
|
|
107
|
-
'danger'
|
|
108
|
-
]),
|
|
85
|
+
color?: 'primary' | 'primary-inverse' | 'secondary' | 'success' | 'danger'
|
|
86
|
+
|
|
109
87
|
/**
|
|
110
88
|
* Override the `Button`'s default focus outline color.
|
|
111
89
|
*/
|
|
112
|
-
focusColor
|
|
90
|
+
focusColor?: 'info' | 'inverse'
|
|
91
|
+
|
|
113
92
|
/**
|
|
114
93
|
* Specifies if the `IconButton` shape should be a circle or rectangle.
|
|
115
94
|
*/
|
|
116
|
-
shape
|
|
95
|
+
shape?: 'rectangle' | 'circle'
|
|
96
|
+
|
|
117
97
|
/**
|
|
118
98
|
* Specifies if the `IconButton` should render with a solid background. When false, the background is transparent.
|
|
119
99
|
*/
|
|
120
|
-
withBackground
|
|
100
|
+
withBackground?: boolean
|
|
101
|
+
|
|
121
102
|
/**
|
|
122
103
|
* Specifies if the `IconButton` should render with a border.
|
|
123
104
|
*/
|
|
124
|
-
withBorder
|
|
105
|
+
withBorder?: boolean
|
|
106
|
+
|
|
125
107
|
/**
|
|
126
108
|
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
127
109
|
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
128
110
|
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
129
111
|
*/
|
|
130
|
-
margin
|
|
112
|
+
margin?: Spacing
|
|
113
|
+
|
|
131
114
|
/**
|
|
132
115
|
* Specify a mouse cursor to use when hovering over the button.
|
|
133
116
|
* The `pointer` cursor is used by default.
|
|
134
117
|
*/
|
|
135
|
-
cursor
|
|
118
|
+
cursor?: Cursor
|
|
119
|
+
|
|
136
120
|
/**
|
|
137
121
|
* Specifies an href attribute for the `IconButton`'s underlying html element.
|
|
138
122
|
*/
|
|
139
|
-
href
|
|
123
|
+
href?: string
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Callback fired when the `Button` is clicked.
|
|
127
|
+
*/
|
|
128
|
+
onClick?: (
|
|
129
|
+
event: React.KeyboardEvent<ViewProps> | React.MouseEvent<ViewProps>
|
|
130
|
+
) => void
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
type PropKeys = keyof IconButtonOwnProps
|
|
134
|
+
|
|
135
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
136
|
+
|
|
137
|
+
type IconButtonProps = IconButtonOwnProps &
|
|
138
|
+
WithStyleProps<BaseButtonTheme, null> &
|
|
139
|
+
OtherHTMLAttributes<IconButtonOwnProps> &
|
|
140
|
+
ToProp
|
|
141
|
+
|
|
142
|
+
const propTypes: PropValidators<PropKeys> = {
|
|
143
|
+
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
144
|
+
renderIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
145
|
+
screenReaderLabel: PropTypes.string.isRequired,
|
|
146
|
+
type: PropTypes.oneOf(['button', 'submit', 'reset']),
|
|
147
|
+
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
148
|
+
elementRef: PropTypes.func,
|
|
149
|
+
as: PropTypes.elementType,
|
|
150
|
+
interaction: PropTypes.oneOf(['enabled', 'disabled', 'readonly']),
|
|
151
|
+
color: PropTypes.oneOf([
|
|
152
|
+
'primary',
|
|
153
|
+
'primary-inverse',
|
|
154
|
+
'secondary',
|
|
155
|
+
'success',
|
|
156
|
+
'danger'
|
|
157
|
+
]),
|
|
158
|
+
focusColor: PropTypes.oneOf(['info', 'inverse']),
|
|
159
|
+
shape: PropTypes.oneOf(['rectangle', 'circle']),
|
|
160
|
+
withBackground: PropTypes.bool,
|
|
161
|
+
withBorder: PropTypes.bool,
|
|
162
|
+
margin: ThemeablePropTypes.spacing,
|
|
163
|
+
cursor: PropTypes.string,
|
|
164
|
+
href: PropTypes.string,
|
|
165
|
+
onClick: PropTypes.func
|
|
140
166
|
}
|
|
141
167
|
|
|
142
168
|
const allowedProps: AllowedPropKeys = [
|
|
@@ -155,7 +181,8 @@ const allowedProps: AllowedPropKeys = [
|
|
|
155
181
|
'size',
|
|
156
182
|
'type',
|
|
157
183
|
'withBackground',
|
|
158
|
-
'withBorder'
|
|
184
|
+
'withBorder',
|
|
185
|
+
'onClick'
|
|
159
186
|
]
|
|
160
187
|
|
|
161
188
|
export type { IconButtonProps }
|