@commercetools-uikit/tooltip 0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339
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/LICENSE +21 -0
- package/README.md +231 -0
- package/dist/commercetools-uikit-tooltip.cjs.d.ts +3 -0
- package/dist/commercetools-uikit-tooltip.cjs.dev.js +338 -0
- package/dist/commercetools-uikit-tooltip.cjs.js +7 -0
- package/dist/commercetools-uikit-tooltip.cjs.prod.js +301 -0
- package/dist/commercetools-uikit-tooltip.esm.js +317 -0
- package/dist/declarations/src/export-types.d.ts +1 -0
- package/dist/declarations/src/index.d.ts +3 -0
- package/dist/declarations/src/tooltip.d.ts +74 -0
- package/dist/declarations/src/version.d.ts +2 -0
- package/package.json +49 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 commercetools GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
<!-- THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -->
|
|
2
|
+
<!-- This file is created by the `yarn generate-readme` script. -->
|
|
3
|
+
|
|
4
|
+
# Tooltip
|
|
5
|
+
|
|
6
|
+
## Description
|
|
7
|
+
|
|
8
|
+
Tooltips display informative text when users hover over or focus on an element.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
yarn add @commercetools-uikit/tooltip
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
npm --save install @commercetools-uikit/tooltip
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Additionally install the peer dependencies (if not present)
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
yarn add react
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
npm --save install react
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```jsx
|
|
33
|
+
import { forwardRef } from 'react';
|
|
34
|
+
import PropTypes from 'prop-types';
|
|
35
|
+
import ReactDOM from 'react-dom';
|
|
36
|
+
import styled from '@emotion/styled';
|
|
37
|
+
import Tooltip from '@commercetools-uikit/tooltip';
|
|
38
|
+
|
|
39
|
+
/* 1. Standard example */
|
|
40
|
+
const ExampleStandard = () => (
|
|
41
|
+
<Tooltip
|
|
42
|
+
placement="left"
|
|
43
|
+
title="If you buy a pizza, you will also get a free ice cream :)"
|
|
44
|
+
>
|
|
45
|
+
<button onClick={() => {}}>Submit</button>
|
|
46
|
+
</Tooltip>
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 2. Working with disabled child elements
|
|
51
|
+
*
|
|
52
|
+
* When you use a tooltip with a disabled element, you should define the
|
|
53
|
+
* style `pointer-events: none` to the disabled element to stop it from capturing events.
|
|
54
|
+
* The Button components from UIKit already support this functionality.
|
|
55
|
+
*/
|
|
56
|
+
const ExampleWithDisabledElements = () => (
|
|
57
|
+
<Tooltip
|
|
58
|
+
placement="left"
|
|
59
|
+
title="You do not have permission to delete the database"
|
|
60
|
+
>
|
|
61
|
+
<button disabled onClick={() => {}} style={{ pointerEvents: 'none' }}>
|
|
62
|
+
Delete production database
|
|
63
|
+
</button>
|
|
64
|
+
</Tooltip>
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 3. Customizing the wrapper
|
|
69
|
+
*
|
|
70
|
+
* The tooltip applies event listeners (`onMouseOver`, `onMouseLeave`, `onFocus`,
|
|
71
|
+
* and `onBlur`) to a wrapping `div` component around the children element.
|
|
72
|
+
* By default, this wrapper is displayed with style `inline-block`.
|
|
73
|
+
* If you want to customize this behaviour, then you can pass in a custom element.
|
|
74
|
+
* Be sure to use `React.forwardRef`, as we need the to pass the ref to the wrapper.
|
|
75
|
+
*/
|
|
76
|
+
const Wrapper = forwardRef((props, ref) => (
|
|
77
|
+
<div ref={ref} style={{ display: 'block' }} {...props}>
|
|
78
|
+
{props.children}
|
|
79
|
+
</div>
|
|
80
|
+
));
|
|
81
|
+
Wrapper.propTypes = {
|
|
82
|
+
children: PropTypes.node.isRequired,
|
|
83
|
+
};
|
|
84
|
+
const FullWidthButton = styled.button`
|
|
85
|
+
display: block;
|
|
86
|
+
width: 100%;
|
|
87
|
+
`;
|
|
88
|
+
const ExampleWithCustomWrapper = () => (
|
|
89
|
+
<Tooltip title="Delete" components={{ WrapperComponent: Wrapper }}>
|
|
90
|
+
<FullWidthButton>Submit</FullWidthButton>
|
|
91
|
+
</Tooltip>
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 4. Customizing the tooltip body
|
|
96
|
+
*
|
|
97
|
+
* You can customize the look and feel of the tooltip body by passing in a custom `BodyComponent`.
|
|
98
|
+
*/
|
|
99
|
+
const Body = styled.div`
|
|
100
|
+
color: red;
|
|
101
|
+
`;
|
|
102
|
+
const ExampleWithCustomBody = () => (
|
|
103
|
+
<Tooltip title="Delete" components={{ BodyComponent: Body }}>
|
|
104
|
+
<button>Submit</button>
|
|
105
|
+
</Tooltip>
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 5. Customizing where the portal is rendered
|
|
110
|
+
*
|
|
111
|
+
* When you are dealing with virtualized components, it can be useful to render
|
|
112
|
+
* the tooltip into another part of the document.
|
|
113
|
+
* You can define a `TooltipWrapperComponent` to do this.
|
|
114
|
+
*/
|
|
115
|
+
const Portal = (props) => ReactDOM.createPortal(props.children, document.body);
|
|
116
|
+
const ExampleWithCustomPortal = () => (
|
|
117
|
+
<Tooltip title="Delete" components={{ TooltipWrapperComponent: Portal }}>
|
|
118
|
+
<button>Submit</button>
|
|
119
|
+
</Tooltip>
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 6. Conditionally displaying tooltips
|
|
124
|
+
*
|
|
125
|
+
* There may be cases when you only want to enable the display of a tooltip under
|
|
126
|
+
* a certain condition. In these cases, you may want to use the `off` prop.
|
|
127
|
+
* In the following example, the tooltip text only appears on hover when the button is disabled.
|
|
128
|
+
*/
|
|
129
|
+
const ExampleWithConditionals = (props) => (
|
|
130
|
+
<Tooltip
|
|
131
|
+
off={props.isDisabled}
|
|
132
|
+
title="You do not have permission to perform this action"
|
|
133
|
+
>
|
|
134
|
+
<button disabled={props.isDisabled}>Submit</button>
|
|
135
|
+
</Tooltip>
|
|
136
|
+
);
|
|
137
|
+
ExampleWithConditionals.propTypes = {
|
|
138
|
+
isDisabled: PropTypes.bool,
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 7. Fine-tuning underlying Popper.js behavior
|
|
143
|
+
*
|
|
144
|
+
* This component uses [Popper.js](https://popper.js.org/) under the hood.
|
|
145
|
+
* Popper provides a way to adjust how tooltip element should behave, by providing
|
|
146
|
+
* a [set of `modifiers`](https://popper.js.org/popper-documentation.html#modifiers).
|
|
147
|
+
* For instance, forcing tooltip to stay in the original placement and not to try
|
|
148
|
+
* flipping when it's getting out of boundaries, can be implemented as following:
|
|
149
|
+
*/
|
|
150
|
+
const ExampleWithCustomPopperBehavior = (props) => (
|
|
151
|
+
<Tooltip
|
|
152
|
+
placement="left"
|
|
153
|
+
title="I will always be on the left side"
|
|
154
|
+
modifiers={{
|
|
155
|
+
preventOverflow: {
|
|
156
|
+
enabled: false,
|
|
157
|
+
},
|
|
158
|
+
flip: {
|
|
159
|
+
enabled: false,
|
|
160
|
+
},
|
|
161
|
+
}}
|
|
162
|
+
>
|
|
163
|
+
<button disabled={props.isDisabled}>Submit</button>
|
|
164
|
+
</Tooltip>
|
|
165
|
+
);
|
|
166
|
+
ExampleWithCustomPopperBehavior.propTypes = {
|
|
167
|
+
isDisabled: PropTypes.bool,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
export {
|
|
171
|
+
ExampleStandard,
|
|
172
|
+
ExampleWithDisabledElements,
|
|
173
|
+
ExampleWithCustomWrapper,
|
|
174
|
+
ExampleWithCustomBody,
|
|
175
|
+
ExampleWithCustomPortal,
|
|
176
|
+
ExampleWithConditionals,
|
|
177
|
+
ExampleWithCustomPopperBehavior,
|
|
178
|
+
};
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Properties
|
|
182
|
+
|
|
183
|
+
| Props | Type | Required | Default | Description |
|
|
184
|
+
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------: | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
185
|
+
| `children` | `ReactElement` | ✅ | | |
|
|
186
|
+
| `showAfter` | `number` | | `300` | Delay (in milliseconds) between the start of the user interaction, and showing the tooltip. |
|
|
187
|
+
| `closeAfter` | `number` | | `200` | Delay (in milliseconds) between the end of the user interaction, and the closing of the tooltip. |
|
|
188
|
+
| `styles` | `Record` | | | Custom css-in-js object styles for the tooltip body. |
|
|
189
|
+
| `off` | `boolean` | | `false` | Determines if the tooltip should not appear. |
|
|
190
|
+
| `id` | `string` | | | An identifier for the tooltip, used for `aria-describedby`. |
|
|
191
|
+
| `onClose` | `Function`<br/>[See signature.](#signature-onclose) | | | A callback function, called when the tooltip is closing. |
|
|
192
|
+
| `onOpen` | `Function`<br/>[See signature.](#signature-onopen) | | | A callback function, called when the tooltip is opening. |
|
|
193
|
+
| `isOpen` | `boolean` | | | |
|
|
194
|
+
| `placement` | `union`<br/>Possible values:<br/>`, 'top', 'top-start', 'top-end', 'right', 'right-start', 'right-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end'` | | `'top'` | How the tooltip is positioned relative to the child element. |
|
|
195
|
+
| `title` | `string` | ✅ | | The message to show in the tooltip. |
|
|
196
|
+
| `modifiers` | `Modifiers` | | | Provides a way to fine-tune an appearance of underlying Popper tooltip element. For more information, please check [Popper.js documentation](https://popper.js.org/popper-documentation.html#modifiers). |
|
|
197
|
+
| `components` | `Object`<br/>[See signature.](#signature-components) | | | Customize the appearance of certain elements of the tooltip. |
|
|
198
|
+
| `horizontalConstraint` | `union`<br/>Possible values:<br/>`, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | `'scale'` | Horizontal size limit of the tooltip. |
|
|
199
|
+
|
|
200
|
+
## Signatures
|
|
201
|
+
|
|
202
|
+
### Signature `onClose`
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
(e?: ChangeEvent | FocusEvent) => void
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Signature `onOpen`
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
(e?: ChangeEvent | FocusEvent) => void
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Signature `components`
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
{
|
|
218
|
+
/**
|
|
219
|
+
* The component rendered as the tooltip body.
|
|
220
|
+
*/
|
|
221
|
+
BodyComponent?: ComponentType;
|
|
222
|
+
/**
|
|
223
|
+
* Where the tooltip should be rendered. This can be useful to render the tooltip into another part of the document, using React portal.
|
|
224
|
+
*/
|
|
225
|
+
TooltipWrapperComponent?: ComponentType;
|
|
226
|
+
/**
|
|
227
|
+
* A custom component wrapper for the tooltip.
|
|
228
|
+
*/
|
|
229
|
+
WrapperComponent?: ComponentType;
|
|
230
|
+
}
|
|
231
|
+
```
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export * from "./declarations/src/index.js";
|
|
2
|
+
export { default } from "./declarations/src/index.js";
|
|
3
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWVyY2V0b29scy11aWtpdC10b29sdGlwLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi9kZWNsYXJhdGlvbnMvc3JjL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
|