@instructure/ui-tooltip 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.
- package/CHANGELOG.md +35 -283
- package/es/Tooltip/{index.js → v1/index.js} +2 -2
- package/es/Tooltip/v2/index.js +163 -0
- package/es/Tooltip/v2/props.js +28 -0
- package/es/Tooltip/v2/styles.js +46 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/{src/index.ts → es/exports/b.js} +1 -2
- package/lib/Tooltip/{index.js → v1/index.js} +3 -3
- package/lib/Tooltip/v2/index.js +173 -0
- package/lib/Tooltip/v2/props.js +33 -0
- package/lib/Tooltip/v2/styles.js +52 -0
- package/lib/{index.js → exports/a.js} +2 -2
- package/lib/exports/b.js +12 -0
- package/package.json +40 -18
- package/src/Tooltip/{index.tsx → v1/index.tsx} +3 -3
- package/src/Tooltip/{props.ts → v1/props.ts} +1 -1
- package/src/Tooltip/v2/README.md +142 -0
- package/src/Tooltip/v2/index.tsx +191 -0
- package/src/Tooltip/v2/props.ts +223 -0
- package/src/Tooltip/v2/styles.ts +52 -0
- package/src/exports/a.ts +28 -0
- package/src/exports/b.ts +28 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Tooltip/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/Tooltip/v1/index.d.ts.map +1 -0
- package/types/Tooltip/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/Tooltip/v1/props.d.ts.map +1 -0
- package/types/Tooltip/v1/styles.d.ts.map +1 -0
- package/types/Tooltip/v1/theme.d.ts.map +1 -0
- package/types/Tooltip/v2/index.d.ts +54 -0
- package/types/Tooltip/v2/index.d.ts.map +1 -0
- package/types/Tooltip/v2/props.d.ts +110 -0
- package/types/Tooltip/v2/props.d.ts.map +1 -0
- package/types/Tooltip/v2/styles.d.ts +13 -0
- package/types/Tooltip/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +3 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +3 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/Tooltip/index.d.ts.map +0 -1
- package/types/Tooltip/props.d.ts.map +0 -1
- package/types/Tooltip/styles.d.ts.map +0 -1
- package/types/Tooltip/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/es/Tooltip/{props.js → v1/props.js} +0 -0
- /package/es/Tooltip/{styles.js → v1/styles.js} +0 -0
- /package/es/Tooltip/{theme.js → v1/theme.js} +0 -0
- /package/lib/Tooltip/{props.js → v1/props.js} +0 -0
- /package/lib/Tooltip/{styles.js → v1/styles.js} +0 -0
- /package/lib/Tooltip/{theme.js → v1/theme.js} +0 -0
- /package/src/Tooltip/{README.md → v1/README.md} +0 -0
- /package/src/Tooltip/{styles.ts → v1/styles.ts} +0 -0
- /package/src/Tooltip/{theme.ts → v1/theme.ts} +0 -0
- /package/types/Tooltip/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/Tooltip/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -35,7 +35,7 @@ import type {
|
|
|
35
35
|
PositionMountNode
|
|
36
36
|
} from '@instructure/ui-position'
|
|
37
37
|
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
38
|
-
import type { PopoverOwnProps } from '@instructure/ui-popover'
|
|
38
|
+
import type { PopoverOwnProps } from '@instructure/ui-popover/v11_6'
|
|
39
39
|
import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
|
|
40
40
|
import { Renderable } from '@instructure/shared-types'
|
|
41
41
|
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
---
|
|
2
|
+
describes: Tooltip
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Tooltips are small text-only contextual overlays that are triggered by hover/focus. Use anywhere additional explanation might be needed but space is limited on the triggering element.
|
|
6
|
+
|
|
7
|
+
> ### What about 'focusable' elements?
|
|
8
|
+
>
|
|
9
|
+
> Content provided to the `renderTip` prop **should not contain any focusable elements**. If you'd like to do
|
|
10
|
+
> that you should use the [Popover](Popover) component and handle focus management yourself or
|
|
11
|
+
> consider using a [Modal](Modal) or a [Tray](Tray) as those will work better on smaller screens.
|
|
12
|
+
|
|
13
|
+
#### Uncontrolled Tooltips
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
---
|
|
17
|
+
type: example
|
|
18
|
+
---
|
|
19
|
+
<div>
|
|
20
|
+
<p>
|
|
21
|
+
<Tooltip
|
|
22
|
+
renderTip="Hello. I'm a tool tip"
|
|
23
|
+
as={Button}
|
|
24
|
+
onShowContent={() => console.log('showing')}
|
|
25
|
+
onHideContent={() => console.log('hidden')}
|
|
26
|
+
>
|
|
27
|
+
Hover or focus me
|
|
28
|
+
</Tooltip>
|
|
29
|
+
</p>
|
|
30
|
+
<p>
|
|
31
|
+
<Tooltip
|
|
32
|
+
color="primary-inverse"
|
|
33
|
+
renderTip="Hello. I'm a tool tip"
|
|
34
|
+
placement="bottom"
|
|
35
|
+
offsetX="5px"
|
|
36
|
+
>
|
|
37
|
+
<TextInput
|
|
38
|
+
display="inline-block"
|
|
39
|
+
renderLabel="Enter some text"
|
|
40
|
+
/>
|
|
41
|
+
</Tooltip>
|
|
42
|
+
</p>
|
|
43
|
+
<p>
|
|
44
|
+
<Tooltip
|
|
45
|
+
renderTip="Hello. I'm a tool tip"
|
|
46
|
+
placement="start"
|
|
47
|
+
on={['click', 'hover', 'focus']}
|
|
48
|
+
>
|
|
49
|
+
<IconButton
|
|
50
|
+
renderIcon={<InfoInstUIIcon color="baseColor"/>}
|
|
51
|
+
withBackground={false}
|
|
52
|
+
withBorder={false}
|
|
53
|
+
screenReaderLabel="Toggle Tooltip"
|
|
54
|
+
/>
|
|
55
|
+
</Tooltip>
|
|
56
|
+
</p>
|
|
57
|
+
</div>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Controlled Tooltips
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
---
|
|
64
|
+
type: example
|
|
65
|
+
---
|
|
66
|
+
const Example = () => {
|
|
67
|
+
const [isShowingContent, setIsShowingContent] = useState(false)
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<>
|
|
71
|
+
<p>
|
|
72
|
+
<Tooltip
|
|
73
|
+
renderTip="Hello. I'm a tool tip"
|
|
74
|
+
isShowingContent={isShowingContent}
|
|
75
|
+
onShowContent={(e) => {
|
|
76
|
+
console.log('expecting to show tooltip')
|
|
77
|
+
}}
|
|
78
|
+
onHideContent={(e) => {
|
|
79
|
+
console.log('expecting to hide tooltip')
|
|
80
|
+
}}
|
|
81
|
+
>
|
|
82
|
+
<Link href="#">This link has a tooltip</Link>
|
|
83
|
+
</Tooltip>
|
|
84
|
+
</p>
|
|
85
|
+
<Checkbox
|
|
86
|
+
label="show tooltip?"
|
|
87
|
+
variant="toggle"
|
|
88
|
+
value="toggled"
|
|
89
|
+
onChange={(event) => {
|
|
90
|
+
setIsShowingContent(event.target.checked)
|
|
91
|
+
}}
|
|
92
|
+
/>
|
|
93
|
+
</>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
render(<Example />)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Custom elements as renderTrigger
|
|
101
|
+
|
|
102
|
+
Popover and Tooltip attach mouse and focus event listeners to their render trigger components via props. These need to be propagated to the component for the listeners to work:
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
---
|
|
106
|
+
type: example
|
|
107
|
+
---
|
|
108
|
+
const MyComponent = forwardRef((props, ref) => {
|
|
109
|
+
return (
|
|
110
|
+
<View background="primary" padding='space12' {...props} ref={ref}>
|
|
111
|
+
My custom component
|
|
112
|
+
</View>
|
|
113
|
+
)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
;<Tooltip renderTip="Tooltip text to display">
|
|
117
|
+
<MyComponent />
|
|
118
|
+
</Tooltip>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Guidelines
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
---
|
|
125
|
+
type: embed
|
|
126
|
+
---
|
|
127
|
+
<Guidelines>
|
|
128
|
+
<Figure recommendation="yes" title="Do">
|
|
129
|
+
<Figure.Item>Use on icons with no labels</Figure.Item>
|
|
130
|
+
<Figure.Item>Use on condensed dates</Figure.Item>
|
|
131
|
+
<Figure.Item>Use on table content if items are getting truncated</Figure.Item>
|
|
132
|
+
<Figure.Item>Use to provide more specific data (ie. user hovers over a chart element, Tooltip shows precise info)</Figure.Item>
|
|
133
|
+
<Figure.Item>Try to stay within 50 characters</Figure.Item>
|
|
134
|
+
</Figure>
|
|
135
|
+
<Figure recommendation="no" title="Don't">
|
|
136
|
+
<Figure.Item>Repeat the exact information contained on the triggering element</Figure.Item>
|
|
137
|
+
<Figure.Item>Contain links or focusable items</Figure.Item>
|
|
138
|
+
<Figure.Item>Use icons inside Tooltips</Figure.Item>
|
|
139
|
+
<Figure.Item>Use in place of a <Link href="/#Popover">Popover</Link> or <Link href="/#Menu">Menu</Link></Figure.Item>
|
|
140
|
+
</Figure>
|
|
141
|
+
</Guidelines>
|
|
142
|
+
```
|
|
@@ -0,0 +1,191 @@
|
|
|
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, ReactNode } from 'react'
|
|
26
|
+
|
|
27
|
+
import {
|
|
28
|
+
getElementType,
|
|
29
|
+
omitProps,
|
|
30
|
+
ensureSingleChild,
|
|
31
|
+
passthroughProps,
|
|
32
|
+
callRenderProp,
|
|
33
|
+
withDeterministicId
|
|
34
|
+
} from '@instructure/ui-react-utils'
|
|
35
|
+
import { Popover } from '@instructure/ui-popover/latest'
|
|
36
|
+
import type { PopoverProps } from '@instructure/ui-popover/latest'
|
|
37
|
+
import { withStyle } from '@instructure/emotion'
|
|
38
|
+
|
|
39
|
+
import generateStyle from './styles'
|
|
40
|
+
|
|
41
|
+
import type { TooltipProps, TooltipState } from './props'
|
|
42
|
+
import { allowedProps } from './props'
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
---
|
|
46
|
+
category: components
|
|
47
|
+
---
|
|
48
|
+
**/
|
|
49
|
+
@withDeterministicId()
|
|
50
|
+
@withStyle(generateStyle)
|
|
51
|
+
class Tooltip extends Component<TooltipProps, TooltipState> {
|
|
52
|
+
static readonly componentId = 'Tooltip'
|
|
53
|
+
|
|
54
|
+
static allowedProps = allowedProps
|
|
55
|
+
|
|
56
|
+
static defaultProps = {
|
|
57
|
+
defaultIsShowingContent: false,
|
|
58
|
+
color: 'primary',
|
|
59
|
+
placement: 'top',
|
|
60
|
+
constrain: 'window',
|
|
61
|
+
offsetX: 0,
|
|
62
|
+
offsetY: 0,
|
|
63
|
+
preventTooltip: false
|
|
64
|
+
} as const
|
|
65
|
+
|
|
66
|
+
private readonly _id: string
|
|
67
|
+
|
|
68
|
+
ref: Element | null = null
|
|
69
|
+
|
|
70
|
+
handleRef = (el: Element | null) => {
|
|
71
|
+
this.ref = el
|
|
72
|
+
if (typeof this.props.elementRef === 'function') {
|
|
73
|
+
this.props.elementRef(el)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
constructor(props: TooltipProps) {
|
|
78
|
+
super(props)
|
|
79
|
+
|
|
80
|
+
this._id = props.deterministicId!()
|
|
81
|
+
|
|
82
|
+
this.state = { hasFocus: false }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
componentDidMount() {
|
|
86
|
+
this.props.makeStyles?.()
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
componentDidUpdate() {
|
|
90
|
+
this.props.makeStyles?.()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
handleFocus: PopoverProps['onFocus'] = () => {
|
|
94
|
+
this.setState({ hasFocus: true })
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
handleBlur: PopoverProps['onBlur'] = () => {
|
|
98
|
+
this.setState({ hasFocus: false })
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
renderTrigger() {
|
|
102
|
+
const { children, as } = this.props as TooltipProps
|
|
103
|
+
const { hasFocus } = this.state
|
|
104
|
+
|
|
105
|
+
const triggerProps = {
|
|
106
|
+
'aria-describedby': this._id
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (as) {
|
|
110
|
+
const Trigger = getElementType(Tooltip, this.props)
|
|
111
|
+
const props = omitProps(this.props, Tooltip.allowedProps)
|
|
112
|
+
return (
|
|
113
|
+
<Trigger {...props} {...triggerProps}>
|
|
114
|
+
{
|
|
115
|
+
children as ReactNode /*TODO check if it can be TooltipRenderChildren, this might cause a crash*/
|
|
116
|
+
}
|
|
117
|
+
</Trigger>
|
|
118
|
+
)
|
|
119
|
+
} else if (typeof children === 'function') {
|
|
120
|
+
return children({
|
|
121
|
+
focused: hasFocus,
|
|
122
|
+
getTriggerProps: (props) => ({
|
|
123
|
+
...triggerProps,
|
|
124
|
+
...props
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
} else {
|
|
128
|
+
return ensureSingleChild(children, triggerProps)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
render() {
|
|
133
|
+
const {
|
|
134
|
+
renderTip,
|
|
135
|
+
isShowingContent,
|
|
136
|
+
defaultIsShowingContent,
|
|
137
|
+
on,
|
|
138
|
+
color,
|
|
139
|
+
placement,
|
|
140
|
+
mountNode,
|
|
141
|
+
constrain,
|
|
142
|
+
offsetX,
|
|
143
|
+
offsetY,
|
|
144
|
+
positionTarget,
|
|
145
|
+
onShowContent,
|
|
146
|
+
onHideContent,
|
|
147
|
+
preventTooltip,
|
|
148
|
+
styles,
|
|
149
|
+
...rest
|
|
150
|
+
} = this.props
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<Popover
|
|
154
|
+
{...passthroughProps(rest)}
|
|
155
|
+
isShowingContent={!preventTooltip && isShowingContent}
|
|
156
|
+
defaultIsShowingContent={!preventTooltip && defaultIsShowingContent}
|
|
157
|
+
on={on}
|
|
158
|
+
shouldRenderOffscreen
|
|
159
|
+
shouldReturnFocus={false}
|
|
160
|
+
placement={placement}
|
|
161
|
+
color={color === 'primary' ? 'primary-inverse' : 'primary'}
|
|
162
|
+
mountNode={mountNode}
|
|
163
|
+
constrain={constrain}
|
|
164
|
+
shadow="resting"
|
|
165
|
+
offsetX={offsetX}
|
|
166
|
+
offsetY={offsetY}
|
|
167
|
+
positionTarget={positionTarget}
|
|
168
|
+
renderTrigger={() => this.renderTrigger()}
|
|
169
|
+
onShowContent={onShowContent}
|
|
170
|
+
onHideContent={onHideContent}
|
|
171
|
+
onFocus={this.handleFocus}
|
|
172
|
+
onBlur={this.handleBlur}
|
|
173
|
+
elementRef={this.handleRef}
|
|
174
|
+
shouldCloseOnDocumentClick={false}
|
|
175
|
+
shouldCloseOnEscape
|
|
176
|
+
shouldSetAriaExpanded={false}
|
|
177
|
+
data-cid="Tooltip"
|
|
178
|
+
>
|
|
179
|
+
{!preventTooltip ? (
|
|
180
|
+
<span id={this._id} css={styles?.tooltip} role="tooltip">
|
|
181
|
+
{/* TODO: figure out how to add a ref to this */}
|
|
182
|
+
{callRenderProp(renderTip)}
|
|
183
|
+
</span>
|
|
184
|
+
) : null}
|
|
185
|
+
</Popover>
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export default Tooltip
|
|
191
|
+
export { Tooltip }
|
|
@@ -0,0 +1,223 @@
|
|
|
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
|
+
|
|
27
|
+
import type {
|
|
28
|
+
AsElementType,
|
|
29
|
+
TooltipTheme,
|
|
30
|
+
OtherHTMLAttributes
|
|
31
|
+
} from '@instructure/shared-types'
|
|
32
|
+
import type {
|
|
33
|
+
PlacementPropValues,
|
|
34
|
+
PositionConstraint,
|
|
35
|
+
PositionMountNode
|
|
36
|
+
} from '@instructure/ui-position'
|
|
37
|
+
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
38
|
+
import type { PopoverOwnProps } from '@instructure/ui-popover/latest'
|
|
39
|
+
import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
|
|
40
|
+
import { Renderable } from '@instructure/shared-types'
|
|
41
|
+
|
|
42
|
+
type TooltipRenderChildrenArgs = {
|
|
43
|
+
focused: boolean
|
|
44
|
+
getTriggerProps: <TriggerProps extends Record<string, any>>(
|
|
45
|
+
props: TriggerProps
|
|
46
|
+
) => { 'aria-describedby': string } & TriggerProps
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type TooltipRenderChildren = (
|
|
50
|
+
args: TooltipRenderChildrenArgs
|
|
51
|
+
) => React.ReactNode
|
|
52
|
+
|
|
53
|
+
type TooltipOwnProps = {
|
|
54
|
+
/**
|
|
55
|
+
* provides a reference to the underlying html root element
|
|
56
|
+
*/
|
|
57
|
+
elementRef?: (element: Element | null) => void
|
|
58
|
+
/**
|
|
59
|
+
* A ReactNode or a function that returns a ReactNode with the following params:
|
|
60
|
+
*
|
|
61
|
+
* @param {Boolean} focused - Is the Tooltip trigger focused?
|
|
62
|
+
* @param {Function} getTriggerProps - Props to be spread onto the trigger element
|
|
63
|
+
*/
|
|
64
|
+
children: React.ReactNode | TooltipRenderChildren
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The content to render in the tooltip
|
|
68
|
+
*/
|
|
69
|
+
renderTip: Renderable
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Whether or not the tooltip content is shown, when controlled
|
|
73
|
+
*/
|
|
74
|
+
isShowingContent?: boolean
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Whether or not to show the content by default, when uncontrolled
|
|
78
|
+
*/
|
|
79
|
+
defaultIsShowingContent?: boolean
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* the element type to render as (assumes a single child if 'as' is undefined)
|
|
83
|
+
*/
|
|
84
|
+
as?: AsElementType
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The action that causes the Content to display (`click`, `hover`, `focus`)
|
|
88
|
+
*/
|
|
89
|
+
on?: ('click' | 'hover' | 'focus') | ('click' | 'hover' | 'focus')[]
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The color of the tooltip content
|
|
93
|
+
*/
|
|
94
|
+
color?: 'primary' | 'primary-inverse'
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Specifies where the Tooltip will be placed in relation to the target element.
|
|
98
|
+
* Ex. placement="bottom" will render the Tooltip below the triggering element
|
|
99
|
+
* (Note: if there is not room, it will position opposite. Ex. "top" will
|
|
100
|
+
* automatically switch to "bottom")
|
|
101
|
+
*/
|
|
102
|
+
placement?: PlacementPropValues
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* An element or a function returning an element to use as the mount node
|
|
106
|
+
* for the `<Tooltip />` (defaults to `document.body`)
|
|
107
|
+
*/
|
|
108
|
+
mountNode?: PositionMountNode
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The parent in which to constrain the tooltip.
|
|
112
|
+
* One of: 'window', 'scroll-parent', 'parent', 'none', an element,
|
|
113
|
+
* or a function returning an element
|
|
114
|
+
*/
|
|
115
|
+
constrain?: PositionConstraint
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The horizontal offset for the positioned content
|
|
119
|
+
*/
|
|
120
|
+
offsetX?: string | number
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The vertical offset for the positioned content
|
|
124
|
+
*/
|
|
125
|
+
offsetY?: string | number
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Target element for positioning the Tooltip (if it differs from children/trigger)
|
|
129
|
+
*/
|
|
130
|
+
positionTarget?: PositionMountNode
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Callback fired when content is shown. When controlled, this callback is
|
|
134
|
+
* fired when the tooltip expects to be shown
|
|
135
|
+
*/
|
|
136
|
+
onShowContent?: (event: React.UIEvent | React.FocusEvent) => void
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Callback fired when content is hidden. When controlled, this callback is
|
|
140
|
+
* fired when the tooltip expects to be hidden
|
|
141
|
+
*/
|
|
142
|
+
onHideContent?: (
|
|
143
|
+
event: React.UIEvent | React.FocusEvent,
|
|
144
|
+
args: { documentClick: boolean }
|
|
145
|
+
) => void
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* If true, it won't display the tooltip. This is useful in cases when tooltip is conditionally needed
|
|
149
|
+
* but in an uncontrolled way
|
|
150
|
+
*/
|
|
151
|
+
preventTooltip?: boolean
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
type PropKeys = keyof TooltipOwnProps
|
|
155
|
+
|
|
156
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
157
|
+
|
|
158
|
+
// passes through props for Popover, except the ones set manually
|
|
159
|
+
type PropsPassableToPopover = Omit<
|
|
160
|
+
PopoverOwnProps,
|
|
161
|
+
| 'isShowingContent'
|
|
162
|
+
| 'defaultIsShowingContent'
|
|
163
|
+
| 'on'
|
|
164
|
+
| 'shouldRenderOffscreen'
|
|
165
|
+
| 'shouldReturnFocus'
|
|
166
|
+
| 'placement'
|
|
167
|
+
| 'color'
|
|
168
|
+
| 'children'
|
|
169
|
+
| 'mountNode'
|
|
170
|
+
| 'constrain'
|
|
171
|
+
| 'shadow'
|
|
172
|
+
| 'offsetX'
|
|
173
|
+
| 'offsetY'
|
|
174
|
+
| 'positionTarget'
|
|
175
|
+
| 'renderTrigger'
|
|
176
|
+
| 'onShowContent'
|
|
177
|
+
| 'onHideContent'
|
|
178
|
+
| 'onFocus'
|
|
179
|
+
| 'onBlur'
|
|
180
|
+
| 'elementRef'
|
|
181
|
+
| 'preventTooltip'
|
|
182
|
+
>
|
|
183
|
+
|
|
184
|
+
type TooltipProps = PropsPassableToPopover &
|
|
185
|
+
TooltipOwnProps &
|
|
186
|
+
WithStyleProps<TooltipTheme, TooltipStyle> &
|
|
187
|
+
// the OtherHTMLAttributes might be passed to the trigger or Popover
|
|
188
|
+
OtherHTMLAttributes<TooltipOwnProps> &
|
|
189
|
+
WithDeterministicIdProps
|
|
190
|
+
|
|
191
|
+
type TooltipStyle = ComponentStyle<'tooltip'>
|
|
192
|
+
|
|
193
|
+
type TooltipState = {
|
|
194
|
+
hasFocus: boolean
|
|
195
|
+
}
|
|
196
|
+
const allowedProps: AllowedPropKeys = [
|
|
197
|
+
'elementRef',
|
|
198
|
+
'children',
|
|
199
|
+
'renderTip',
|
|
200
|
+
'isShowingContent',
|
|
201
|
+
'defaultIsShowingContent',
|
|
202
|
+
'as',
|
|
203
|
+
'on',
|
|
204
|
+
'color',
|
|
205
|
+
'placement',
|
|
206
|
+
'mountNode',
|
|
207
|
+
'constrain',
|
|
208
|
+
'offsetX',
|
|
209
|
+
'offsetY',
|
|
210
|
+
'positionTarget',
|
|
211
|
+
'onShowContent',
|
|
212
|
+
'onHideContent',
|
|
213
|
+
'preventTooltip'
|
|
214
|
+
]
|
|
215
|
+
|
|
216
|
+
export type {
|
|
217
|
+
TooltipProps,
|
|
218
|
+
TooltipState,
|
|
219
|
+
TooltipStyle,
|
|
220
|
+
TooltipRenderChildren,
|
|
221
|
+
TooltipRenderChildrenArgs
|
|
222
|
+
}
|
|
223
|
+
export { allowedProps }
|
|
@@ -0,0 +1,52 @@
|
|
|
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 } from '@instructure/ui-themes'
|
|
26
|
+
import type { TooltipStyle } 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
|
+
* @return {Object} The final style object, which will be used in the component
|
|
35
|
+
*/
|
|
36
|
+
const generateStyle = (
|
|
37
|
+
componentTheme: NewComponentTypes['Tooltip']
|
|
38
|
+
): TooltipStyle => {
|
|
39
|
+
return {
|
|
40
|
+
tooltip: {
|
|
41
|
+
label: 'tooltip',
|
|
42
|
+
fontFamily: componentTheme.fontFamily,
|
|
43
|
+
fontWeight: componentTheme.fontWeight,
|
|
44
|
+
boxSizing: 'border-box',
|
|
45
|
+
display: 'block',
|
|
46
|
+
fontSize: componentTheme.fontSize,
|
|
47
|
+
padding: componentTheme.padding
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default generateStyle
|
package/src/exports/a.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
export { Tooltip } from '../Tooltip/v1'
|
|
25
|
+
export type {
|
|
26
|
+
TooltipProps,
|
|
27
|
+
TooltipRenderChildrenArgs
|
|
28
|
+
} from '../Tooltip/v1/props'
|
package/src/exports/b.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
export { Tooltip } from '../Tooltip/v2'
|
|
25
|
+
export type {
|
|
26
|
+
TooltipProps,
|
|
27
|
+
TooltipRenderChildrenArgs
|
|
28
|
+
} from '../Tooltip/v2/props'
|