Skip to content

Commit fdef7d8

Browse files
authored
feat(core): expand Relative Color Syntax across components (#37)
* feat(core): expand Relative Color Syntax across components * refactor(docs): reorder theme imports and improve button and theme styles * fix(core): enhance button, card, and tooltip styles for RCS * fix(core): adjust min-width for better responsiveness in tooltips
1 parent 89bcd8c commit fdef7d8

12 files changed

Lines changed: 92 additions & 216 deletions

File tree

apps/docs/astro.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import mdx from '@astrojs/mdx';
22
import { defineConfig } from 'astro/config';
33
import critters from 'astro-critters';
4-
import shiftLight from './src/themes/shift-light.json' with { type: 'json' };
5-
import shiftDark from './src/themes/shift-dark.json' with { type: 'json' };
64
import { oklchTransformer } from './src/lib/oklch-transformer';
5+
import shiftDark from './src/themes/shift-dark.json' with { type: 'json' };
6+
import shiftLight from './src/themes/shift-light.json' with { type: 'json' };
77

88
export default defineConfig({
99
site: 'https://getshiftcss.com',

apps/docs/src/lib/oklch-transformer.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface ShikiTransformer {
1818

1919
// Convert sRGB to linear RGB (remove gamma correction)
2020
function srgbToLinear(c: number): number {
21-
return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
21+
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
2222
}
2323

2424
// Convert linear RGB to XYZ (D65 illuminant)
@@ -86,13 +86,15 @@ function hexToOklch(hex: string): string {
8686

8787
// Transform both light and dark color values in a style string
8888
function transformStyleColors(style: string): string {
89-
return style.replace(
90-
/color:\s*#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b/g,
91-
(_, hex) => `color:${hexToOklch('#' + expandHex(hex))}`
92-
).replace(
93-
/--shiki-dark:\s*#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b/g,
94-
(_, hex) => `--shiki-dark:${hexToOklch('#' + expandHex(hex))}`
95-
);
89+
return style
90+
.replace(
91+
/color:\s*#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b/g,
92+
(_, hex) => `color:${hexToOklch(`#${expandHex(hex)}`)}`
93+
)
94+
.replace(
95+
/--shiki-dark:\s*#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b/g,
96+
(_, hex) => `--shiki-dark:${hexToOklch(`#${expandHex(hex)}`)}`
97+
);
9698
}
9799

98100
// Expand 3-digit hex to 6-digit
@@ -105,9 +107,8 @@ function expandHex(hex: string): string {
105107

106108
// Transform all hex colors in a style string (for pre element)
107109
function transformAllHexColors(style: string): string {
108-
return style.replace(
109-
/#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b/g,
110-
(_, hex) => hexToOklch('#' + expandHex(hex))
110+
return style.replace(/#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})\b/g, (_, hex) =>
111+
hexToOklch(`#${expandHex(hex)}`)
111112
);
112113
}
113114

apps/docs/src/pages/demo.astro

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ import DocsLayout from '../components/layout/DocsLayout.astro';
274274
<h3>Dot Indicators</h3>
275275
<p style="font-size: var(--s-text-sm); color: var(--s-text-secondary); margin-bottom: var(--s-space-2);">Size variants also apply to dots.</p>
276276
<div class="demo-row">
277-
<span s-badge="success" s-dot aria-label="Success status"></span>
278-
<span s-badge="warning" s-dot aria-label="Warning status"></span>
279-
<span s-badge="danger" s-dot aria-label="Danger status"></span>
277+
<span s-badge="success" s-dot role="status" aria-label="Success status"></span>
278+
<span s-badge="warning" s-dot role="status" aria-label="Warning status"></span>
279+
<span s-badge="danger" s-dot role="status" aria-label="Danger status"></span>
280280
</div>
281281

282282
<h3>In Context</h3>

apps/docs/src/styles/theme.css

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -127,90 +127,7 @@ select[s-input] {
127127
border-radius: var(--s-radius) !important;
128128
}
129129

130-
/* Primary button - hollow with glow */
131-
[s-btn="primary"] {
132-
background: var(--s-primary);
133-
border: var(--s-border-width) solid var(--s-primary);
134-
color: #fff;
135-
text-transform: uppercase;
136-
letter-spacing: 0.08em;
137-
font-weight: 700;
138-
139-
&:hover {
140-
background: var(--s-primary);
141-
color: #fff;
142-
box-shadow: var(--s-glow);
143-
}
144-
}
145-
146-
/* Secondary button - subtle */
147-
[s-btn="secondary"] {
148-
background: transparent;
149-
border: var(--s-border-width) solid var(--void-300);
150-
color: var(--void-700);
151-
text-transform: uppercase;
152-
letter-spacing: 0.05em;
153-
154-
&:hover {
155-
border-color: var(--s-primary);
156-
color: var(--s-primary);
157-
}
158-
}
159-
160-
/* Ghost button */
161-
[s-btn="ghost"] {
162-
text-transform: uppercase;
163-
letter-spacing: 0.05em;
164-
165-
&:hover {
166-
background: var(--void-100);
167-
}
168-
}
169-
170-
/* Link button */
171-
[s-btn="link"] {
172-
color: var(--s-primary);
173-
text-decoration: underline;
174-
text-decoration-color: transparent;
175-
text-underline-offset: 0.2em;
176-
177-
&:hover {
178-
color: oklch(40% 0.2 var(--shift-hue-primary));
179-
text-decoration-color: currentColor;
180-
}
181-
}
182-
183-
/* Light mode: darken link buttons for contrast */
184-
[data-theme="light"] [s-btn="link"] {
185-
color: oklch(35% 0.2 var(--shift-hue-primary));
186-
187-
&:hover {
188-
color: oklch(25% 0.25 var(--shift-hue-primary));
189-
}
190-
}
191-
192-
/* Dark mode: explicit button text colors for a11y tools */
193-
[data-theme="dark"] [s-btn="primary"] {
194-
color: #1a1a1a;
195-
}
196-
197-
[data-theme="dark"] [s-btn="success"],
198-
[data-theme="dark"] [s-btn="warning"],
199-
[data-theme="dark"] [s-btn="danger"] {
200-
color: #1a1a1a;
201-
}
202-
203-
[data-theme="dark"] [s-btn="outline"] {
204-
color: var(--s-primary);
205-
}
206-
207-
[data-theme="dark"] [s-btn="secondary"] {
208-
color: var(--void-900);
209-
}
210-
211-
[data-theme="dark"] [s-btn="ghost"] {
212-
color: var(--void-900);
213-
}
130+
/* Button styling now handled by core framework with RCS */
214131

215132
/* Cards - sharp with subtle border */
216133
[s-card] {

apps/docs/src/themes/shift-dark.json

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,14 @@
4242
},
4343
{
4444
"name": "Function",
45-
"scope": [
46-
"entity.name.function",
47-
"support.function",
48-
"meta.function-call"
49-
],
45+
"scope": ["entity.name.function", "support.function", "meta.function-call"],
5046
"settings": {
5147
"foreground": "#c4b5fd"
5248
}
5349
},
5450
{
5551
"name": "Class",
56-
"scope": [
57-
"entity.name.class",
58-
"entity.name.type.class",
59-
"support.class"
60-
],
52+
"scope": ["entity.name.class", "entity.name.type.class", "support.class"],
6153
"settings": {
6254
"foreground": "#fcd34d"
6355
}
@@ -71,11 +63,7 @@
7163
},
7264
{
7365
"name": "Property",
74-
"scope": [
75-
"variable.other.property",
76-
"support.type.property-name",
77-
"meta.object-literal.key"
78-
],
66+
"scope": ["variable.other.property", "support.type.property-name", "meta.object-literal.key"],
7967
"settings": {
8068
"foreground": "#67e8f9"
8169
}
@@ -94,10 +82,7 @@
9482
},
9583
{
9684
"name": "CSS Value",
97-
"scope": [
98-
"support.constant.property-value.css",
99-
"meta.property-value.css"
100-
],
85+
"scope": ["support.constant.property-value.css", "meta.property-value.css"],
10186
"settings": {
10287
"foreground": "#6ee7b7"
10388
}
@@ -118,10 +103,7 @@
118103
},
119104
{
120105
"name": "Attribute Value",
121-
"scope": [
122-
"string.quoted.double.html",
123-
"string.quoted.single.html"
124-
],
106+
"scope": ["string.quoted.double.html", "string.quoted.single.html"],
125107
"settings": {
126108
"foreground": "#6ee7b7"
127109
}
@@ -135,22 +117,14 @@
135117
},
136118
{
137119
"name": "Punctuation",
138-
"scope": [
139-
"punctuation",
140-
"meta.brace",
141-
"punctuation.definition.string"
142-
],
120+
"scope": ["punctuation", "meta.brace", "punctuation.definition.string"],
143121
"settings": {
144122
"foreground": "#a3a3a3"
145123
}
146124
},
147125
{
148126
"name": "Type",
149-
"scope": [
150-
"entity.name.type",
151-
"support.type",
152-
"support.type.primitive"
153-
],
127+
"scope": ["entity.name.type", "support.type", "support.type.primitive"],
154128
"settings": {
155129
"foreground": "#67e8f9"
156130
}

apps/docs/src/themes/shift-light.json

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,14 @@
4242
},
4343
{
4444
"name": "Function",
45-
"scope": [
46-
"entity.name.function",
47-
"support.function",
48-
"meta.function-call"
49-
],
45+
"scope": ["entity.name.function", "support.function", "meta.function-call"],
5046
"settings": {
5147
"foreground": "#7c3aed"
5248
}
5349
},
5450
{
5551
"name": "Class",
56-
"scope": [
57-
"entity.name.class",
58-
"entity.name.type.class",
59-
"support.class"
60-
],
52+
"scope": ["entity.name.class", "entity.name.type.class", "support.class"],
6153
"settings": {
6254
"foreground": "#b45309"
6355
}
@@ -71,11 +63,7 @@
7163
},
7264
{
7365
"name": "Property",
74-
"scope": [
75-
"variable.other.property",
76-
"support.type.property-name",
77-
"meta.object-literal.key"
78-
],
66+
"scope": ["variable.other.property", "support.type.property-name", "meta.object-literal.key"],
7967
"settings": {
8068
"foreground": "#0891b2"
8169
}
@@ -94,10 +82,7 @@
9482
},
9583
{
9684
"name": "CSS Value",
97-
"scope": [
98-
"support.constant.property-value.css",
99-
"meta.property-value.css"
100-
],
85+
"scope": ["support.constant.property-value.css", "meta.property-value.css"],
10186
"settings": {
10287
"foreground": "#047857"
10388
}
@@ -118,10 +103,7 @@
118103
},
119104
{
120105
"name": "Attribute Value",
121-
"scope": [
122-
"string.quoted.double.html",
123-
"string.quoted.single.html"
124-
],
106+
"scope": ["string.quoted.double.html", "string.quoted.single.html"],
125107
"settings": {
126108
"foreground": "#047857"
127109
}
@@ -135,22 +117,14 @@
135117
},
136118
{
137119
"name": "Punctuation",
138-
"scope": [
139-
"punctuation",
140-
"meta.brace",
141-
"punctuation.definition.string"
142-
],
120+
"scope": ["punctuation", "meta.brace", "punctuation.definition.string"],
143121
"settings": {
144122
"foreground": "#525252"
145123
}
146124
},
147125
{
148126
"name": "Type",
149-
"scope": [
150-
"entity.name.type",
151-
"support.type",
152-
"support.type.primitive"
153-
],
127+
"scope": ["entity.name.type", "support.type", "support.type.primitive"],
154128
"settings": {
155129
"foreground": "#0891b2"
156130
}

0 commit comments

Comments
 (0)