Skip to content

Commit 8f4b4a0

Browse files
committed
refactor: Enhance Select component color handling with dynamic CSS variable retrieval
1 parent b61e8d2 commit 8f4b4a0

File tree

4 files changed

+42
-38
lines changed

4 files changed

+42
-38
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@programmer_network/yail",
3-
"version": "1.0.205",
3+
"version": "1.0.206",
44
"description": "Programmer Network's official UI library for React",
55
"author": "Aleksandar Grbic - (https://programmer.network)",
66
"publishConfig": {

src/Components/Inputs/Input/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ const Input: FC<IInputProps> = forwardRef<HTMLInputElement, IInputProps>(
5656
return (
5757
<div className={classNames(inputWrapperClassName)}>
5858
<InputHeader {...inputHeaderProps} />
59-
dsadsa
6059
<div className='yl:flex yl:flex-col'>
6160
<input
6261
ref={ref}

src/Components/Inputs/Select/styles.ts

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,43 @@ import { CSSObjectWithLabel, OptionProps, StylesConfig } from "react-select";
22

33
import { Option } from "./types";
44

5-
/**
6-
* @url https://react-select.com/styles
7-
*/
5+
const getCssVar = (varName: string): string => {
6+
return getComputedStyle(document.documentElement)
7+
.getPropertyValue(varName)
8+
.trim();
9+
};
810

9-
const color = "oklch(0.85 0.02 240)";
11+
const text = getCssVar("--color-text") || "oklch(0.85 0.02 240)";
12+
const background = getCssVar("--color-background") || "oklch(0.1 0.02 240)";
13+
const border = getCssVar("--color-border") || "oklch(0.3 0.02 240)";
14+
const muted = getCssVar("--color-muted") || "oklch(0.5 0.05 240)";
15+
const primary = getCssVar("--color-primary") || "oklch(0.8 0.2 80)";
16+
const secondary = getCssVar("--color-secondary") || "oklch(0.65 0.05 270)";
17+
const error = getCssVar("--color-error") || "oklch(0.6 0.2 30)";
18+
const accent = getCssVar("--color-accent") || "oklch(0.6 0.2 250)";
1019

1120
export const styles: StylesConfig<Option | undefined, false | true> = {
1221
input: (base: CSSObjectWithLabel) => ({
1322
...base,
1423
outline: "none",
1524
boxShadow: "none",
1625
padding: "4px 0",
17-
color,
26+
color: text,
1827
"input:focus": {
1928
boxShadow: "none"
2029
}
2130
}),
2231
control: (base: CSSObjectWithLabel) => {
2332
return {
2433
...base,
25-
backgroundColor: "oklch(0.1 0.02 240)",
34+
backgroundColor: background,
2635
borderWidth: "2px",
27-
borderColor: "oklch(0.3 0.02 240)",
36+
borderColor: border,
2837
borderRadius: 6,
2938
boxShadow: "none",
30-
color,
39+
color: text,
3140
"&:hover": {
32-
borderColor: "oklch(0.3 0.02 240)"
41+
borderColor: border
3342
}
3443
};
3544
},
@@ -38,51 +47,49 @@ export const styles: StylesConfig<Option | undefined, false | true> = {
3847
props: OptionProps<Option | undefined, false | true>
3948
) => ({
4049
...base,
41-
backgroundColor: props.isDisabled
42-
? "oklch(0.5 0.05 240)"
43-
: "oklch(0.1 0.02 240)",
44-
color: props.isDisabled ? "oklch(0.5 0.05 240)" : color,
50+
backgroundColor: props.isDisabled ? muted : background,
51+
color: props.isDisabled ? muted : text,
4552
cursor: props.isDisabled ? "not-allowed" : "default",
4653
"&:active": {
47-
backgroundColor: !props.isDisabled ? "oklch(0.6 0.2 250)" : undefined,
48-
color: !props.isDisabled ? color : undefined
54+
backgroundColor: !props.isDisabled ? primary : undefined,
55+
color: !props.isDisabled ? background : undefined
4956
}
5057
}),
5158
multiValueRemove: (base: CSSObjectWithLabel) => {
5259
return {
5360
...base,
54-
color: "oklch(0.65 0.05 270)",
61+
color: secondary,
5562
cursor: "pointer",
5663
"&:hover": {
57-
color: color,
58-
backgroundColor: "oklch(0.6 0.2 30)"
64+
color: text,
65+
backgroundColor: error
5966
}
6067
};
6168
},
6269
multiValue: (base: CSSObjectWithLabel) => {
6370
return {
6471
...base,
65-
backgroundColor: "oklch(0.1 0.02 240)",
66-
color
72+
backgroundColor: background,
73+
color: text
6774
};
6875
},
6976
singleValue: (base: CSSObjectWithLabel) => {
7077
return {
7178
...base,
72-
backgroundColor: "oklch(0.1 0.02 240)",
73-
color
79+
backgroundColor: background,
80+
color: text
7481
};
7582
},
7683
multiValueLabel: (base: CSSObjectWithLabel) => {
7784
return {
7885
...base,
79-
color
86+
color: text
8087
};
8188
},
8289
placeholder: (base: CSSObjectWithLabel) => {
8390
return {
8491
...base,
85-
color: "oklch(0.5 0.05 240)"
92+
color: muted
8693
};
8794
},
8895
valueContainer: (base: CSSObjectWithLabel) => {
@@ -97,28 +104,28 @@ export const styles: StylesConfig<Option | undefined, false | true> = {
97104
menu: (base: CSSObjectWithLabel) => {
98105
return {
99106
...base,
100-
backgroundColor: "oklch(0.1 0.02 240)",
101-
color,
107+
backgroundColor: background,
108+
color: text,
102109
boxShadow: "none",
103110
borderWidth: "2px",
104-
borderColor: "oklch(0.3 0.02 240)",
111+
borderColor: border,
105112
borderRadius: 0,
106113
zIndex: 99999999
107114
};
108115
},
109116
indicatorSeparator: (base: CSSObjectWithLabel) => {
110117
return {
111118
...base,
112-
backgroundColor: "oklch(0.3 0.02 240)"
119+
backgroundColor: border
113120
};
114121
},
115122
clearIndicator: (base: CSSObjectWithLabel) => {
116123
return {
117124
...base,
118-
color: "oklch(0.3 0.02 240)",
125+
color: border,
119126
cursor: "pointer",
120127
"&:hover": {
121-
color: "oklch(0.6 0.2 30)"
128+
color: error
122129
}
123130
};
124131
},
@@ -129,18 +136,18 @@ export const styles: StylesConfig<Option | undefined, false | true> = {
129136
width: "10px"
130137
},
131138
"::-webkit-scrollbar-track": {
132-
background: "oklch(0.1 0.02 240)"
139+
background: background
133140
},
134141
"::-webkit-scrollbar-thumb": {
135-
background: "oklch(0.3 0.02 240)"
142+
background: border
136143
},
137144
"::-webkit-scrollbar-thumb:hover": {
138-
background: "oklch(0.6 0.2 250)"
145+
background: accent
139146
}
140147
}),
141148
groupHeading: (base: CSSObjectWithLabel) => ({
142149
...base,
143-
color: "oklch(0.5 0.05 240)",
150+
color: muted,
144151
padding: "5px 10px",
145152
fontSize: "0.75rem"
146153
})

src/tailwind.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
}
1616

1717
@theme {
18-
/* Colors */
1918
--color-primary: oklch(0.8 0.2 80);
2019
--color-secondary: oklch(0.65 0.05 270);
2120
--color-background: oklch(0.1 0.02 240);
@@ -29,7 +28,6 @@
2928
--color-error: oklch(0.6 0.2 30);
3029
--color-info: oklch(0.6 0.2 250);
3130

32-
/* Animations */
3331
--animate-height-animation: height-animation 100ms
3432
cubic-bezier(0.3, 0.31, 0.59, 0.7);
3533

0 commit comments

Comments
 (0)