Skip to content

Commit 68e0bed

Browse files
authored
feat(outline): migrate to css outline (#627)
1 parent 9861170 commit 68e0bed

File tree

7 files changed

+45
-16
lines changed

7 files changed

+45
-16
lines changed

.changeset/three-bugs-tie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cube-dev/ui-kit': minor
3+
---
4+
5+
Migration to modern rgb definition.

.changeset/twelve-humans-smoke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cube-dev/ui-kit': patch
3+
---
4+
5+
Use native css outline for outline style.

src/components/organisms/FileTabs/FileTabs.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ const TabElement = tasty(Action, {
108108
fontWeight: 500,
109109
opacity: 1,
110110
preset: 'default',
111-
outline: {
112-
'': 'inset #purple-03.0',
113-
'focused & focus-visible': 'inset #purple-03',
111+
shadow: {
112+
'': 'inset 0 0 0 1ow #purple-03.0',
113+
'focused & focus-visible': 'inset 0 0 0 1ow #purple-03',
114114
},
115115
transform: {
116116
'': 'translate(0, 0)',

src/tasty/styles/boxShadow.combinator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Deprecated: left as an example
12
export function boxShadowCombinator(styles) {
23
const values = boxShadowCombinator.__lookupStyles.reduce(
34
(list: string[], style) => {

src/tasty/styles/outline.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,39 @@
1-
import { parseStyle } from '../utils/styles';
1+
import { filterMods, parseStyle } from '../utils/styles';
22

3+
const BORDER_STYLES = [
4+
'none',
5+
'hidden',
6+
'dotted',
7+
'dashed',
8+
'solid',
9+
'double',
10+
'groove',
11+
'ridge',
12+
'inset',
13+
'outset',
14+
];
15+
16+
/**
17+
*
18+
* @param outline
19+
* @return {{outline: string}|*}
20+
*/
321
export function outlineStyle({ outline }) {
4-
if (!outline && outline !== 0) return '';
22+
if (!outline && outline !== 0) return;
523

624
if (outline === true) outline = '1ow';
725

8-
const { values, color, mods } = parseStyle(String(outline));
26+
const { values, mods, color } = parseStyle(String(outline));
27+
28+
const typeMods = filterMods(mods, BORDER_STYLES);
929

10-
const inset = mods.includes('inset');
11-
const size = values[0] || 'var(--outline-width)';
30+
const value = values[0] || 'var(--outline-width)';
31+
const type = typeMods[0] || 'solid';
1232
const outlineColor = color || 'var(--outline-color)';
1333

14-
return {
15-
'--local-outline-box-shadow': `${
16-
inset ? 'inset ' : ''
17-
}0 0 0 ${size} ${outlineColor}`,
18-
};
34+
const styleValue = [value, type, outlineColor].join(' ');
35+
36+
return { outline: styleValue };
1937
}
2038

2139
outlineStyle.__lookupStyles = ['outline'];

src/tasty/styles/predefined.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import { fontStyle } from './font';
2626
import { outlineStyle } from './outline';
2727
import { transitionStyle } from './transition';
2828
import { groupRadiusAttr } from './groupRadius';
29-
import { boxShadowCombinator } from './boxShadow.combinator';
3029
import { styledScrollbarStyle } from './styledScrollbar';
3130
import { displayStyle } from './display';
3231
import { alignStyle } from './align';
@@ -149,6 +148,8 @@ export function predefine() {
149148
.map((s, i) => (i ? columnsConverter : rowsConverter)(s))
150149
.join('/');
151150
});
151+
// Other styles
152+
defineStyleAlias('outlineOffset', 'outlineOffset', numberConverter);
152153

153154
[
154155
displayStyle,
@@ -172,7 +173,6 @@ export function predefine() {
172173
alignStyle,
173174
justifyStyle,
174175
presetStyle,
175-
boxShadowCombinator,
176176
outlineStyle,
177177
fontStyle,
178178
fontStyleStyle,

src/tasty/styles/shadow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function shadowStyle({ shadow }) {
1414
if (shadow === true) shadow = '0 5px 15px #shadow';
1515

1616
return {
17-
'--local-shadow-box-shadow': shadow.split(',').map(toBoxShadow).join(','),
17+
'box-shadow': shadow.split(',').map(toBoxShadow).join(','),
1818
};
1919
}
2020

0 commit comments

Comments
 (0)