Skip to content

Commit 1c24df5

Browse files
cp-sumi-kSam Henderson
andauthored
Add dark mode support (#37)
* add dark mode * Fixed dark mode --------- Co-authored-by: Sam Henderson <[email protected]>
1 parent 2ab2638 commit 1c24df5

3 files changed

Lines changed: 142 additions & 99 deletions

File tree

admin/src/components/Input.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { Flex, Field } from "@strapi/design-system";
55
import { useIntl } from "react-intl";
66
import TagsInput from "react-tagsinput";
77
import Autosuggest from "react-autosuggest";
8-
import { css } from "./styles/global.ts";
8+
import { getStyling } from "./styles/global";
9+
10+
const ThemeStyle = getStyling(localStorage.getItem("STRAPI_THEME"));
911

1012
const Tags = ({
1113
attribute,
@@ -160,7 +162,6 @@ const Tags = ({
160162

161163
return (
162164
<>
163-
<style>{css}</style>
164165
<Field.Root
165166
name={name}
166167
id={name}
@@ -178,6 +179,7 @@ const Tags = ({
178179
<Field.Label action={labelAction}>
179180
{intlLabel && formatMessage({ id: intlLabel })}
180181
</Field.Label>
182+
<ThemeStyle />
181183
<Flex direction="column">
182184
<TagsInput
183185
value={tags}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import { createGlobalStyle, css } from "styled-components";
2+
3+
const light = css`
4+
:root {
5+
--primary: #7b79ff;
6+
--secondary: rgb(255, 255, 255);
7+
--text: #32324d;
8+
--input-background: #ffffff;
9+
--input-border: #dcdce4;
10+
--tag-background: #f0f0ff;
11+
--tag-text: #4945ff;
12+
--suggestion-background: #ffffff;
13+
--suggestion-hover: #f6f6f9;
14+
}
15+
`;
16+
17+
const dark = css`
18+
:root {
19+
--primary: #7b79ff;
20+
--secondary: rgb(33, 33, 52);
21+
--text: #ffffff;
22+
--input-background: #181826;
23+
--input-border: #4a4a6a;
24+
--tag-background: #7b79ff;
25+
--tag-text: #ffffff;
26+
--suggestion-background: #181826;
27+
--suggestion-hover: #212134;
28+
}
29+
`;
30+
31+
const styles = css`
32+
.react-tagsinput {
33+
width: 100%;
34+
border: 1px solid var(--input-border);
35+
border-radius: 4px;
36+
overflow: hidden;
37+
padding-left: 5px;
38+
padding-top: 5px;
39+
}
40+
41+
.react-tagsinput--focused {
42+
outline: 3px solid var(--primary);
43+
}
44+
45+
.react-tagsinput-tag {
46+
background-color: var(--tag-background);
47+
border-radius: 2px;
48+
border: 1px solid var(--tag-background);
49+
color: var(--tag-text);
50+
display: inline-block;
51+
font-family: sans-serif;
52+
font-size: 13px;
53+
font-weight: 400;
54+
margin-bottom: 5px;
55+
margin-right: 5px;
56+
padding: 5px;
57+
}
58+
59+
.react-tagsinput-remove {
60+
cursor: pointer;
61+
font-weight: bold;
62+
}
63+
64+
.react-tagsinput-tag a::before {
65+
content: " ×";
66+
}
67+
68+
.react-tagsinput-input {
69+
background: transparent;
70+
border: 0;
71+
color: var(--text);
72+
font-family: sans-serif;
73+
font-size: 13px;
74+
font-weight: 400;
75+
margin-bottom: 6px;
76+
margin-top: 1px;
77+
outline: none;
78+
padding: 5px;
79+
width: 100%;
80+
}
81+
82+
.react-tagsinput > span {
83+
display: flex;
84+
flex-flow: wrap;
85+
}
86+
87+
.react-autosuggest__container {
88+
display: flex;
89+
flex-direction: column;
90+
flex: auto;
91+
}
92+
93+
.react-autosuggest__suggestions-container {
94+
position: absolute;
95+
z-index: 200;
96+
width: 280px;
97+
margin: 0;
98+
padding: 0;
99+
list-style-type: none;
100+
background-color: var(--suggestion-background);
101+
}
102+
103+
.react-autosuggest__suggestions-container--open {
104+
border: 1px solid var(--input-border);
105+
}
106+
107+
.react-autosuggest__suggestion {
108+
cursor: pointer;
109+
padding: 10px 20px;
110+
}
111+
112+
.react-autosuggest__suggestion > span {
113+
font-size: 13px;
114+
font-weight: 400;
115+
}
116+
117+
.react-autosuggest__suggestion--highlighted,
118+
.react-autosuggest__suggestion--focused {
119+
background-color: var(--suggestion-hover);
120+
}
121+
`;
122+
123+
export const getStyling = (theme) => {
124+
let themeStyle = light;
125+
126+
switch (theme) {
127+
case 'dark':
128+
themeStyle = dark;
129+
break;
130+
default:
131+
themeStyle = light;
132+
}
133+
134+
return createGlobalStyle`
135+
${themeStyle}
136+
${styles}
137+
`;
138+
};

admin/src/components/styles/global.ts

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)