Skip to content

Commit b328052

Browse files
committed
docs(api): update api with styles and include theming section
1 parent 7b4b5ef commit b328052

File tree

3 files changed

+69
-17
lines changed

3 files changed

+69
-17
lines changed

README.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ Checkout out my <u use:tooltip={{ content: 'Hello World!' }}>tooltip</u>
4848
| content | The string or object containing componentref and props | `string` | `object` component (default: ``) |
4949
| maxWidth | The max allowable width of the tooltip content | `number` (default: `200`) |
5050
| position | The position where the tooltip should appear relative to its parent | `string` (default: `top`) |
51-
| theme | The CSS theme class name | `string` (default: ``) |
51+
| theme | The CSS theme class name | `string` (default: ``) |
52+
| styles | The object containing theme variable overrides | `object` (default: `null`) |
5253

5354
#### Using components as content
5455
| Prop | Description | Value |
@@ -65,6 +66,57 @@ Checkout out my <u use:tooltip={{ content: 'Hello World!' }}>tooltip</u>
6566
Checkout out my <span use:tooltip={{ content: { component: ComponentAsTooltip, props: { title: 'Hello World!' } } }}>tooltip</span>
6667
```
6768

69+
## Theming
70+
You can customize tooltips theme using several methods:
71+
- Assign a theme class name via the `theme` property that includes all of your CSS variables overrides
72+
- Define the overrides directly using the `styles` property
73+
- Override the CSS variables globally
74+
75+
Tooltip CSS variables:
76+
77+
```css
78+
--tooltip-background-color: rgba(0, 0, 0, 0.9);
79+
--tooltip-border-radius: 4px;
80+
--tooltip-box-shadow: 0 1px 20px rgba(0, 0, 0, 0.25);
81+
--tooltip-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell,
82+
'Helvetica Neue', sans-serif;
83+
--tooltip-font-size: 14px;
84+
--tooltip-font-weight: 500;
85+
--tooltip-line-height: 1.25rem;
86+
--tooltip-color: #fff;
87+
--tooltip-offset-x: 12px;
88+
--tooltip-offset-y: 12px;
89+
--tooltip-padding: 12px;
90+
--tooltip-z-index: 100;
91+
--tooltip-arrow-size: 10px;
92+
```
93+
94+
### Using the theme property
95+
96+
```svelte
97+
// action
98+
<span title="hello world!" use:tooltip={{ theme: 'custom-tooltip' }}>Hover over me</span>
99+
100+
// component
101+
<Tooltip content="hello world!" theme="custom-tooltip">Hover over me</Tooltip>
102+
103+
<style>
104+
:global(.tooltip.custom-tooltip) {
105+
--tooltip-background-color: hotpink;
106+
--tooltip-box-shadow: 0 1px 8px pink;
107+
}
108+
</style>
109+
```
110+
111+
### Using the style property
112+
```svelte
113+
// action
114+
<span title="hello world!" use:tooltip={{ style: { backgroundColor: 'blue', borderRadius: '10px' } }}>Hover over me</span>
115+
116+
// component
117+
<Tooltip content="hello world!" style={{ style: { backgroundColor: 'blue' } }}>Hover over me</Tooltip>
118+
```
119+
68120
## Changelog
69121

70122
[Changelog](CHANGELOG.md)

src/action-tooltip.svelte

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
let minWidth = 0;
1616
let component = null;
1717
18-
const opposite = {
18+
const inverse = {
1919
left: 'right',
2020
right: 'left',
2121
top: 'bottom',
@@ -63,7 +63,7 @@
6363
}
6464
6565
if (autoPosition && !isInViewport()) {
66-
position = opposite[position];
66+
position = inverse[position];
6767
}
6868
6969
ref.classList.add('show');
@@ -92,8 +92,8 @@
9292

9393
<style>
9494
/*--------------------------*
95-
* Theme Variables
96-
*--------------------------*/
95+
* Theme Variables
96+
*--------------------------*/
9797
9898
:root {
9999
--tooltip-background-color: rgba(0, 0, 0, 0.9);
@@ -113,8 +113,8 @@
113113
}
114114
115115
/*--------------------------*
116-
* Tooltip Styling
117-
*--------------------------*/
116+
* Tooltip Styling
117+
*--------------------------*/
118118
119119
.tooltip {
120120
background-color: var(--tooltip-background-color);
@@ -203,8 +203,8 @@
203203
}
204204
205205
/*--------------------------*
206-
* CSS Animations
207-
*--------------------------*/
206+
* CSS Animations
207+
*--------------------------*/
208208
209209
/* Fade */
210210

src/tooltip.svelte

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
let minWidth = 0;
1717
let component = null;
1818
19-
const opposite = {
19+
const inverse = {
2020
left: 'right',
2121
right: 'left',
2222
top: 'bottom',
@@ -36,7 +36,7 @@
3636
3737
const onMouseEnter = () => {
3838
if (autoPosition && !isInViewport()) {
39-
position = opposite[position];
39+
position = inverse[position];
4040
}
4141
4242
tooltipRef.classList.add('show');
@@ -113,8 +113,8 @@
113113

114114
<style>
115115
/*--------------------------*
116-
* Theme Variables
117-
*--------------------------*/
116+
* Theme Variables
117+
*--------------------------*/
118118
119119
:root {
120120
--tooltip-background-color: rgba(0, 0, 0, 0.9);
@@ -134,8 +134,8 @@
134134
}
135135
136136
/*--------------------------*
137-
* Tooltip Styling
138-
*--------------------------*/
137+
* Tooltip Styling
138+
*--------------------------*/
139139
140140
.tooltip-container {
141141
position: relative;
@@ -232,8 +232,8 @@
232232
}
233233
234234
/*--------------------------*
235-
* CSS Animations
236-
*--------------------------*/
235+
* CSS Animations
236+
*--------------------------*/
237237
238238
/* Fade */
239239

0 commit comments

Comments
 (0)