@instructure/ui-buttons 8.8.1-snapshot.7 → 8.9.1-snapshot.2
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 +6 -0
- package/es/BaseButton/index.js +12 -133
- package/es/BaseButton/props.js +138 -0
- package/es/Button/index.js +4 -87
- package/es/Button/props.js +107 -0
- package/es/CloseButton/index.js +5 -93
- package/es/CloseButton/props.js +103 -0
- package/es/CondensedButton/index.js +4 -65
- package/es/CondensedButton/props.js +86 -0
- package/es/IconButton/index.js +4 -91
- package/es/IconButton/props.js +111 -0
- package/es/ToggleButton/index.js +2 -77
- package/es/ToggleButton/props.js +100 -0
- package/lib/BaseButton/index.js +12 -133
- package/lib/BaseButton/props.js +150 -0
- package/lib/Button/index.js +4 -87
- package/lib/Button/props.js +119 -0
- package/lib/CloseButton/index.js +5 -93
- package/lib/CloseButton/props.js +115 -0
- package/lib/CondensedButton/index.js +4 -65
- package/lib/CondensedButton/props.js +98 -0
- package/lib/IconButton/index.js +4 -91
- package/lib/IconButton/props.js +123 -0
- package/lib/ToggleButton/index.js +3 -79
- package/lib/ToggleButton/props.js +112 -0
- package/package.json +21 -21
- package/src/BaseButton/index.tsx +15 -120
- package/src/BaseButton/props.ts +192 -0
- package/src/BaseButton/styles.ts +1 -1
- package/src/Button/index.tsx +7 -81
- package/src/Button/props.ts +149 -0
- package/src/CloseButton/index.tsx +8 -82
- package/src/CloseButton/props.ts +137 -0
- package/src/CloseButton/styles.ts +1 -1
- package/src/CondensedButton/index.tsx +7 -57
- package/src/CondensedButton/props.ts +118 -0
- package/src/IconButton/index.tsx +7 -84
- package/src/IconButton/props.ts +154 -0
- package/src/ToggleButton/index.tsx +5 -68
- package/src/ToggleButton/props.ts +140 -0
- package/src/index.ts +6 -6
- package/types/BaseButton/index.d.ts +47 -101
- package/types/BaseButton/index.d.ts.map +1 -1
- package/types/BaseButton/{types.d.ts → props.d.ts} +15 -10
- package/types/BaseButton/props.d.ts.map +1 -0
- package/types/BaseButton/styles.d.ts +1 -1
- package/types/Button/index.d.ts +36 -73
- package/types/Button/index.d.ts.map +1 -1
- package/types/Button/{types.d.ts → props.d.ts} +12 -4
- package/types/Button/props.d.ts.map +1 -0
- package/types/CloseButton/index.d.ts +41 -75
- package/types/CloseButton/index.d.ts.map +1 -1
- package/types/CloseButton/props.d.ts +27 -0
- package/types/CloseButton/props.d.ts.map +1 -0
- package/types/CloseButton/styles.d.ts +1 -1
- package/types/CondensedButton/index.d.ts +28 -55
- package/types/CondensedButton/index.d.ts.map +1 -1
- package/types/CondensedButton/props.d.ts +24 -0
- package/types/CondensedButton/props.d.ts.map +1 -0
- package/types/IconButton/index.d.ts +38 -76
- package/types/IconButton/index.d.ts.map +1 -1
- package/types/IconButton/{types.d.ts → props.d.ts} +11 -3
- package/types/IconButton/props.d.ts.map +1 -0
- package/types/ToggleButton/index.d.ts +34 -65
- package/types/ToggleButton/index.d.ts.map +1 -1
- package/types/ToggleButton/{types.d.ts → props.d.ts} +10 -3
- package/types/ToggleButton/props.d.ts.map +1 -0
- package/types/index.d.ts +6 -6
- package/es/BaseButton/types.js +0 -1
- package/es/Button/types.js +0 -1
- package/es/CloseButton/types.js +0 -1
- package/es/CondensedButton/types.js +0 -1
- package/es/IconButton/types.js +0 -1
- package/es/ToggleButton/types.js +0 -1
- package/lib/BaseButton/types.js +0 -1
- package/lib/Button/types.js +0 -1
- package/lib/CloseButton/types.js +0 -1
- package/lib/CondensedButton/types.js +0 -1
- package/lib/IconButton/types.js +0 -1
- package/lib/ToggleButton/types.js +0 -1
- package/src/BaseButton/types.ts +0 -58
- package/src/Button/types.ts +0 -44
- package/src/CloseButton/types.ts +0 -45
- package/src/CondensedButton/types.ts +0 -40
- package/src/IconButton/types.ts +0 -45
- package/src/ToggleButton/types.ts +0 -48
- package/types/BaseButton/types.d.ts.map +0 -1
- package/types/Button/types.d.ts.map +0 -1
- package/types/CloseButton/types.d.ts +0 -22
- package/types/CloseButton/types.d.ts.map +0 -1
- package/types/CondensedButton/types.d.ts +0 -16
- package/types/CondensedButton/types.d.ts.map +0 -1
- package/types/IconButton/types.d.ts.map +0 -1
- package/types/ToggleButton/types.d.ts.map +0 -1
package/src/IconButton/index.tsx
CHANGED
|
@@ -23,17 +23,18 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
import React, { Component } from 'react'
|
|
26
|
-
import PropTypes from 'prop-types'
|
|
27
26
|
|
|
28
27
|
import { testable } from '@instructure/ui-testable'
|
|
29
28
|
import { passthroughProps } from '@instructure/ui-react-utils'
|
|
30
29
|
import { ScreenReaderContent } from '@instructure/ui-a11y-content'
|
|
31
30
|
|
|
32
|
-
import { withStyle
|
|
31
|
+
import { withStyle } from '@instructure/emotion'
|
|
33
32
|
|
|
34
33
|
import generateComponentTheme from './theme'
|
|
35
34
|
import { BaseButton } from '../BaseButton'
|
|
36
|
-
|
|
35
|
+
|
|
36
|
+
import { propTypes, allowedProps } from './props'
|
|
37
|
+
import type { IconButtonProps } from './props'
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
40
|
---
|
|
@@ -47,100 +48,22 @@ category: components
|
|
|
47
48
|
class IconButton extends Component<IconButtonProps> {
|
|
48
49
|
static readonly componentId = 'IconButton'
|
|
49
50
|
|
|
50
|
-
static propTypes =
|
|
51
|
-
|
|
52
|
-
* An icon, or function returning an icon (identical to the `renderIcon` prop).
|
|
53
|
-
*/
|
|
54
|
-
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
55
|
-
/**
|
|
56
|
-
* An icon, or function that returns an icon (identical to the `children` prop).
|
|
57
|
-
*/
|
|
58
|
-
renderIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
59
|
-
/**
|
|
60
|
-
* An accessible label for the `IconButton`.
|
|
61
|
-
*/
|
|
62
|
-
screenReaderLabel: PropTypes.string.isRequired,
|
|
63
|
-
/**
|
|
64
|
-
* Specifies the type of the `IconButton`'s underlying html element.
|
|
65
|
-
*/
|
|
66
|
-
type: PropTypes.oneOf(['button', 'submit', 'reset']),
|
|
67
|
-
/**
|
|
68
|
-
* The size of the `IconButton`
|
|
69
|
-
*/
|
|
70
|
-
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
71
|
-
/**
|
|
72
|
-
* Provides a reference to the `IconButton`'s underlying html element.
|
|
73
|
-
*/
|
|
74
|
-
elementRef: PropTypes.func,
|
|
75
|
-
/**
|
|
76
|
-
* The element to render as the component root, `button` by default.
|
|
77
|
-
*/
|
|
78
|
-
as: PropTypes.elementType,
|
|
79
|
-
/**
|
|
80
|
-
* Specifies if interaction with the `IconButton` is enabled, disabled, or readonly.
|
|
81
|
-
*/
|
|
82
|
-
interaction: PropTypes.oneOf(['enabled', 'disabled', 'readonly']),
|
|
83
|
-
/**
|
|
84
|
-
* Specifies the color for the `IconButton`.
|
|
85
|
-
*/
|
|
86
|
-
color: PropTypes.oneOf([
|
|
87
|
-
'primary',
|
|
88
|
-
'primary-inverse',
|
|
89
|
-
'secondary',
|
|
90
|
-
'success',
|
|
91
|
-
'danger'
|
|
92
|
-
]),
|
|
93
|
-
/**
|
|
94
|
-
* Override the `Button`'s default focus outline color.
|
|
95
|
-
*/
|
|
96
|
-
focusColor: PropTypes.oneOf(['info', 'inverse']),
|
|
97
|
-
/**
|
|
98
|
-
* Specifies if the `IconButton` shape should be a circle or rectangle.
|
|
99
|
-
*/
|
|
100
|
-
shape: PropTypes.oneOf(['rectangle', 'circle']),
|
|
101
|
-
/**
|
|
102
|
-
* Specifies if the `IconButton` should render with a solid background. When false, the background is transparent.
|
|
103
|
-
*/
|
|
104
|
-
withBackground: PropTypes.bool,
|
|
105
|
-
/**
|
|
106
|
-
* Specifies if the `IconButton` should render with a border.
|
|
107
|
-
*/
|
|
108
|
-
withBorder: PropTypes.bool,
|
|
109
|
-
/**
|
|
110
|
-
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
111
|
-
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
112
|
-
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
113
|
-
*/
|
|
114
|
-
margin: ThemeablePropTypes.spacing,
|
|
115
|
-
/**
|
|
116
|
-
* Specify a mouse cursor to use when hovering over the button.
|
|
117
|
-
* The `pointer` cursor is used by default.
|
|
118
|
-
*/
|
|
119
|
-
cursor: PropTypes.string,
|
|
120
|
-
/**
|
|
121
|
-
* Specifies an href attribute for the `IconButton`'s underlying html element.
|
|
122
|
-
*/
|
|
123
|
-
href: PropTypes.string
|
|
124
|
-
}
|
|
125
|
-
|
|
51
|
+
static propTypes = propTypes
|
|
52
|
+
static allowedProps = allowedProps
|
|
126
53
|
static defaultProps = {
|
|
127
54
|
children: null,
|
|
128
|
-
renderIcon: undefined,
|
|
129
55
|
type: 'button',
|
|
130
56
|
size: 'medium',
|
|
131
57
|
// @ts-expect-error ts-migrate(6133) FIXME: 'el' is declared but its value is never read.
|
|
132
58
|
elementRef: (el) => {},
|
|
133
59
|
as: 'button',
|
|
134
60
|
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
135
|
-
interaction: undefined,
|
|
136
61
|
color: 'secondary',
|
|
137
|
-
focusColor: undefined,
|
|
138
62
|
shape: 'rectangle',
|
|
139
63
|
withBackground: true,
|
|
140
64
|
withBorder: true,
|
|
141
65
|
margin: '0',
|
|
142
|
-
cursor: 'pointer'
|
|
143
|
-
href: undefined
|
|
66
|
+
cursor: 'pointer'
|
|
144
67
|
}
|
|
145
68
|
|
|
146
69
|
_baseButton = null
|
|
@@ -0,0 +1,154 @@
|
|
|
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 PropTypes from 'prop-types'
|
|
27
|
+
|
|
28
|
+
import { ThemeablePropTypes } from '@instructure/emotion'
|
|
29
|
+
|
|
30
|
+
import type { Spacing } from '@instructure/emotion'
|
|
31
|
+
import type { AsElementType, PropValidators } from '@instructure/shared-types'
|
|
32
|
+
|
|
33
|
+
type IconButtonOwnProps = {
|
|
34
|
+
children?: React.ReactNode | ((...args: any[]) => React.ReactNode)
|
|
35
|
+
renderIcon?: React.ReactNode | ((...args: any[]) => any)
|
|
36
|
+
screenReaderLabel: string
|
|
37
|
+
type?: 'button' | 'submit' | 'reset'
|
|
38
|
+
size?: 'small' | 'medium' | 'large'
|
|
39
|
+
elementRef?: (...args: any[]) => any
|
|
40
|
+
as?: AsElementType
|
|
41
|
+
interaction?: 'enabled' | 'disabled' | 'readonly'
|
|
42
|
+
color?: 'primary' | 'primary-inverse' | 'secondary' | 'success' | 'danger'
|
|
43
|
+
focusColor?: 'info' | 'inverse'
|
|
44
|
+
shape?: 'rectangle' | 'circle'
|
|
45
|
+
withBackground?: boolean
|
|
46
|
+
withBorder?: boolean
|
|
47
|
+
margin?: Spacing
|
|
48
|
+
cursor?: string
|
|
49
|
+
href?: string
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
type PropKeys = keyof IconButtonOwnProps
|
|
53
|
+
|
|
54
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
55
|
+
|
|
56
|
+
type IconButtonProps = IconButtonOwnProps
|
|
57
|
+
|
|
58
|
+
const propTypes: PropValidators<PropKeys> = {
|
|
59
|
+
/**
|
|
60
|
+
* An icon, or function returning an icon (identical to the `renderIcon` prop).
|
|
61
|
+
*/
|
|
62
|
+
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
63
|
+
/**
|
|
64
|
+
* An icon, or function that returns an icon (identical to the `children` prop).
|
|
65
|
+
*/
|
|
66
|
+
renderIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
67
|
+
/**
|
|
68
|
+
* An accessible label for the `IconButton`.
|
|
69
|
+
*/
|
|
70
|
+
screenReaderLabel: PropTypes.string.isRequired,
|
|
71
|
+
/**
|
|
72
|
+
* Specifies the type of the `IconButton`'s underlying html element.
|
|
73
|
+
*/
|
|
74
|
+
type: PropTypes.oneOf(['button', 'submit', 'reset']),
|
|
75
|
+
/**
|
|
76
|
+
* The size of the `IconButton`
|
|
77
|
+
*/
|
|
78
|
+
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
79
|
+
/**
|
|
80
|
+
* Provides a reference to the `IconButton`'s underlying html element.
|
|
81
|
+
*/
|
|
82
|
+
elementRef: PropTypes.func,
|
|
83
|
+
/**
|
|
84
|
+
* The element to render as the component root, `button` by default.
|
|
85
|
+
*/
|
|
86
|
+
as: PropTypes.elementType,
|
|
87
|
+
/**
|
|
88
|
+
* Specifies if interaction with the `IconButton` is enabled, disabled, or readonly.
|
|
89
|
+
*/
|
|
90
|
+
interaction: PropTypes.oneOf(['enabled', 'disabled', 'readonly']),
|
|
91
|
+
/**
|
|
92
|
+
* Specifies the color for the `IconButton`.
|
|
93
|
+
*/
|
|
94
|
+
color: PropTypes.oneOf([
|
|
95
|
+
'primary',
|
|
96
|
+
'primary-inverse',
|
|
97
|
+
'secondary',
|
|
98
|
+
'success',
|
|
99
|
+
'danger'
|
|
100
|
+
]),
|
|
101
|
+
/**
|
|
102
|
+
* Override the `Button`'s default focus outline color.
|
|
103
|
+
*/
|
|
104
|
+
focusColor: PropTypes.oneOf(['info', 'inverse']),
|
|
105
|
+
/**
|
|
106
|
+
* Specifies if the `IconButton` shape should be a circle or rectangle.
|
|
107
|
+
*/
|
|
108
|
+
shape: PropTypes.oneOf(['rectangle', 'circle']),
|
|
109
|
+
/**
|
|
110
|
+
* Specifies if the `IconButton` should render with a solid background. When false, the background is transparent.
|
|
111
|
+
*/
|
|
112
|
+
withBackground: PropTypes.bool,
|
|
113
|
+
/**
|
|
114
|
+
* Specifies if the `IconButton` should render with a border.
|
|
115
|
+
*/
|
|
116
|
+
withBorder: PropTypes.bool,
|
|
117
|
+
/**
|
|
118
|
+
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
119
|
+
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
120
|
+
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
121
|
+
*/
|
|
122
|
+
margin: ThemeablePropTypes.spacing,
|
|
123
|
+
/**
|
|
124
|
+
* Specify a mouse cursor to use when hovering over the button.
|
|
125
|
+
* The `pointer` cursor is used by default.
|
|
126
|
+
*/
|
|
127
|
+
cursor: PropTypes.string,
|
|
128
|
+
/**
|
|
129
|
+
* Specifies an href attribute for the `IconButton`'s underlying html element.
|
|
130
|
+
*/
|
|
131
|
+
href: PropTypes.string
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const allowedProps: AllowedPropKeys = [
|
|
135
|
+
'as',
|
|
136
|
+
'children',
|
|
137
|
+
'color',
|
|
138
|
+
'cursor',
|
|
139
|
+
'elementRef',
|
|
140
|
+
'focusColor',
|
|
141
|
+
'href',
|
|
142
|
+
'interaction',
|
|
143
|
+
'margin',
|
|
144
|
+
'renderIcon',
|
|
145
|
+
'screenReaderLabel',
|
|
146
|
+
'shape',
|
|
147
|
+
'size',
|
|
148
|
+
'type',
|
|
149
|
+
'withBackground',
|
|
150
|
+
'withBorder'
|
|
151
|
+
]
|
|
152
|
+
|
|
153
|
+
export type { IconButtonProps }
|
|
154
|
+
export { propTypes, allowedProps }
|
|
@@ -23,16 +23,16 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
import React, { Component } from 'react'
|
|
26
|
-
import PropTypes from 'prop-types'
|
|
27
26
|
|
|
28
27
|
import { testable } from '@instructure/ui-testable'
|
|
29
|
-
import { PositionPropTypes } from '@instructure/ui-position'
|
|
30
28
|
|
|
31
29
|
import { callRenderProp, passthroughProps } from '@instructure/ui-react-utils'
|
|
32
30
|
|
|
33
31
|
import { Tooltip } from '@instructure/ui-tooltip'
|
|
34
32
|
import { IconButton } from '../IconButton'
|
|
35
|
-
|
|
33
|
+
|
|
34
|
+
import { propTypes, allowedProps } from './props'
|
|
35
|
+
import type { ToggleButtonProps } from './props'
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
---
|
|
@@ -44,81 +44,18 @@ category: components
|
|
|
44
44
|
class ToggleButton extends Component<ToggleButtonProps> {
|
|
45
45
|
static readonly componentId = 'ToggleButton'
|
|
46
46
|
|
|
47
|
-
static propTypes =
|
|
48
|
-
|
|
49
|
-
* Text to output only to screen readers
|
|
50
|
-
*/
|
|
51
|
-
screenReaderLabel: PropTypes.string.isRequired,
|
|
52
|
-
/**
|
|
53
|
-
* Text to render in the tooltip shown on hover/focus
|
|
54
|
-
*/
|
|
55
|
-
renderTooltipContent: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
|
|
56
|
-
.isRequired,
|
|
57
|
-
/**
|
|
58
|
-
* An icon or function that returns an icon
|
|
59
|
-
*/
|
|
60
|
-
renderIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
|
|
61
|
-
.isRequired,
|
|
62
|
-
/**
|
|
63
|
-
* Toggles the `aria-pressed` attribute on the button (`true` if `pressed`; `false` if `unpressed`)
|
|
64
|
-
*/
|
|
65
|
-
status: PropTypes.oneOf(['pressed', 'unpressed']).isRequired,
|
|
66
|
-
/**
|
|
67
|
-
* The element to render as the component root; `button` by default
|
|
68
|
-
*/
|
|
69
|
-
as: PropTypes.elementType,
|
|
70
|
-
/**
|
|
71
|
-
* Specifies if interaction with `ToggleButton` is `enabled`, `disabled`, or `readonly`
|
|
72
|
-
*/
|
|
73
|
-
interaction: PropTypes.oneOf(['enabled', 'disabled', 'readonly']),
|
|
74
|
-
/**
|
|
75
|
-
* The size of the `ToggleButton`
|
|
76
|
-
*/
|
|
77
|
-
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
78
|
-
/**
|
|
79
|
-
* Provides a reference to `ToggleButton`'s underlying HTML element
|
|
80
|
-
*/
|
|
81
|
-
elementRef: PropTypes.func,
|
|
82
|
-
/**
|
|
83
|
-
* Callback fired when the `ToggleButton` is clicked
|
|
84
|
-
*/
|
|
85
|
-
onClick: PropTypes.func,
|
|
86
|
-
/**
|
|
87
|
-
* The color in which to display the icon
|
|
88
|
-
*/
|
|
89
|
-
color: PropTypes.string,
|
|
90
|
-
/**
|
|
91
|
-
* By default, the tooltip will show on hover/focus. Use this prop if you need to override that behavior.
|
|
92
|
-
*/
|
|
93
|
-
isShowingTooltip: PropTypes.bool,
|
|
94
|
-
/**
|
|
95
|
-
* An element or a function returning an element to use as the mount node
|
|
96
|
-
*/
|
|
97
|
-
mountNode: PositionPropTypes.mountNode,
|
|
98
|
-
/**
|
|
99
|
-
* The placement of the tooltip in relation to the button
|
|
100
|
-
*/
|
|
101
|
-
placement: PositionPropTypes.placement,
|
|
102
|
-
/**
|
|
103
|
-
* The parent in which to constrain the tooltip.
|
|
104
|
-
* One of: 'window', 'scroll-parent', 'parent', 'none', an element,
|
|
105
|
-
* or a function returning an element.
|
|
106
|
-
*/
|
|
107
|
-
constrain: PositionPropTypes.constrain
|
|
108
|
-
}
|
|
109
|
-
|
|
47
|
+
static propTypes = propTypes
|
|
48
|
+
static allowedProps = allowedProps
|
|
110
49
|
static defaultProps = {
|
|
111
50
|
size: 'medium',
|
|
112
51
|
as: 'button',
|
|
113
52
|
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
114
|
-
interaction: undefined,
|
|
115
53
|
// @ts-expect-error ts-migrate(6133) FIXME: 'el' is declared but its value is never read.
|
|
116
54
|
elementRef: (el) => {},
|
|
117
55
|
renderIcon: () => {},
|
|
118
56
|
onClick: () => {},
|
|
119
57
|
mountNode: null,
|
|
120
58
|
color: 'secondary',
|
|
121
|
-
isShowingTooltip: undefined,
|
|
122
59
|
placement: 'top center',
|
|
123
60
|
constrain: 'window'
|
|
124
61
|
}
|
|
@@ -0,0 +1,140 @@
|
|
|
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 PropTypes from 'prop-types'
|
|
27
|
+
|
|
28
|
+
import { PositionPropTypes } from '@instructure/ui-position'
|
|
29
|
+
|
|
30
|
+
import type { AsElementType, PropValidators } from '@instructure/shared-types'
|
|
31
|
+
import type {
|
|
32
|
+
PlacementPropValues,
|
|
33
|
+
PositionConstraint,
|
|
34
|
+
PositionMountNode
|
|
35
|
+
} from '@instructure/ui-position'
|
|
36
|
+
|
|
37
|
+
type ToggleButtonOwnProps = {
|
|
38
|
+
screenReaderLabel: string
|
|
39
|
+
renderTooltipContent: React.ReactNode | ((...args: any[]) => any)
|
|
40
|
+
renderIcon: React.ReactNode | ((...args: any[]) => any)
|
|
41
|
+
status: 'pressed' | 'unpressed'
|
|
42
|
+
as?: AsElementType
|
|
43
|
+
interaction?: 'enabled' | 'disabled' | 'readonly'
|
|
44
|
+
size?: 'small' | 'medium' | 'large'
|
|
45
|
+
elementRef?: (...args: any[]) => any
|
|
46
|
+
onClick?: (...args: any[]) => any
|
|
47
|
+
color?: string
|
|
48
|
+
isShowingTooltip?: boolean
|
|
49
|
+
mountNode?: PositionMountNode
|
|
50
|
+
placement?: PlacementPropValues
|
|
51
|
+
constrain?: PositionConstraint
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type PropKeys = keyof ToggleButtonOwnProps
|
|
55
|
+
|
|
56
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
57
|
+
|
|
58
|
+
type ToggleButtonProps = ToggleButtonOwnProps
|
|
59
|
+
|
|
60
|
+
const propTypes: PropValidators<PropKeys> = {
|
|
61
|
+
/**
|
|
62
|
+
* Text to output only to screen readers
|
|
63
|
+
*/
|
|
64
|
+
screenReaderLabel: PropTypes.string.isRequired,
|
|
65
|
+
/**
|
|
66
|
+
* Text to render in the tooltip shown on hover/focus
|
|
67
|
+
*/
|
|
68
|
+
renderTooltipContent: PropTypes.oneOfType([PropTypes.node, PropTypes.func])
|
|
69
|
+
.isRequired,
|
|
70
|
+
/**
|
|
71
|
+
* An icon or function that returns an icon
|
|
72
|
+
*/
|
|
73
|
+
renderIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
|
|
74
|
+
/**
|
|
75
|
+
* Toggles the `aria-pressed` attribute on the button (`true` if `pressed`; `false` if `unpressed`)
|
|
76
|
+
*/
|
|
77
|
+
status: PropTypes.oneOf(['pressed', 'unpressed']).isRequired,
|
|
78
|
+
/**
|
|
79
|
+
* The element to render as the component root; `button` by default
|
|
80
|
+
*/
|
|
81
|
+
as: PropTypes.elementType,
|
|
82
|
+
/**
|
|
83
|
+
* Specifies if interaction with `ToggleButton` is `enabled`, `disabled`, or `readonly`
|
|
84
|
+
*/
|
|
85
|
+
interaction: PropTypes.oneOf(['enabled', 'disabled', 'readonly']),
|
|
86
|
+
/**
|
|
87
|
+
* The size of the `ToggleButton`
|
|
88
|
+
*/
|
|
89
|
+
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
90
|
+
/**
|
|
91
|
+
* Provides a reference to `ToggleButton`'s underlying HTML element
|
|
92
|
+
*/
|
|
93
|
+
elementRef: PropTypes.func,
|
|
94
|
+
/**
|
|
95
|
+
* Callback fired when the `ToggleButton` is clicked
|
|
96
|
+
*/
|
|
97
|
+
onClick: PropTypes.func,
|
|
98
|
+
/**
|
|
99
|
+
* The color in which to display the icon
|
|
100
|
+
*/
|
|
101
|
+
color: PropTypes.string,
|
|
102
|
+
/**
|
|
103
|
+
* By default, the tooltip will show on hover/focus. Use this prop if you need to override that behavior.
|
|
104
|
+
*/
|
|
105
|
+
isShowingTooltip: PropTypes.bool,
|
|
106
|
+
/**
|
|
107
|
+
* An element or a function returning an element to use as the mount node
|
|
108
|
+
*/
|
|
109
|
+
mountNode: PositionPropTypes.mountNode,
|
|
110
|
+
/**
|
|
111
|
+
* The placement of the tooltip in relation to the button
|
|
112
|
+
*/
|
|
113
|
+
placement: PositionPropTypes.placement,
|
|
114
|
+
/**
|
|
115
|
+
* The parent in which to constrain the tooltip.
|
|
116
|
+
* One of: 'window', 'scroll-parent', 'parent', 'none', an element,
|
|
117
|
+
* or a function returning an element.
|
|
118
|
+
*/
|
|
119
|
+
constrain: PositionPropTypes.constrain
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const allowedProps: AllowedPropKeys = [
|
|
123
|
+
'as',
|
|
124
|
+
'color',
|
|
125
|
+
'constrain',
|
|
126
|
+
'elementRef',
|
|
127
|
+
'interaction',
|
|
128
|
+
'isShowingTooltip',
|
|
129
|
+
'mountNode',
|
|
130
|
+
'onClick',
|
|
131
|
+
'placement',
|
|
132
|
+
'renderIcon',
|
|
133
|
+
'renderTooltipContent',
|
|
134
|
+
'screenReaderLabel',
|
|
135
|
+
'size',
|
|
136
|
+
'status'
|
|
137
|
+
]
|
|
138
|
+
|
|
139
|
+
export type { ToggleButtonProps }
|
|
140
|
+
export { propTypes, allowedProps }
|