Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dark mode #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions admin/src/components/Input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const Tags = ({
const apiUrl = attribute?.options?.apiUrl || "";
const attrName = apiUrl.slice(apiUrl.lastIndexOf("=") + 1) || "name";
const inputEle = useRef(null);
const theme = window.localStorage?.STRAPI_THEME; // "light" or "dark"

const [tags, setTags] = useState(() => {
try {
Expand Down Expand Up @@ -121,37 +122,43 @@ const Tags = ({
e.preventDefault();
} else {
props.onChange(e);
getSuggestions(); // Fetch suggestions on input change
}
};

const handleOnFocus = () => {
getSuggestions(); // Fetch suggestions on focus
};

const inputValue = (props.value && props.value.trim()) || "";
const inputLength = inputValue.length;

let s = suggestions.data || [];
if (s.length <= 0) {
getSuggestions();
}

if (inputLength > 0) {
if (inputLength > 0) {
s = s
.filter((state) => {
const suggestionName = state[attrName] || "";
return suggestionName.toLowerCase().slice(0, inputLength) === inputValue;
return suggestionName.toLowerCase().startsWith(inputValue.toLowerCase());
})
.map((state) => ({
id: state.id,
[attrName]: state[attrName] || "",
}));
}

return (
<Autosuggest
ref={props.ref}
suggestions={s}
shouldRenderSuggestions={(value) => value && value.trim().length > 0}
getSuggestionValue={(s) => s[attrName]}
renderSuggestion={(s) => <span>{s[attrName]}</span>}
inputProps={{ ...props, onChange: handleOnChange }}
inputProps={{
...props,
onChange: handleOnChange,
onFocus: handleOnFocus, // Add onFocus handler
}}
onSuggestionSelected={(_, { suggestion }) => props.addTag(suggestion[attrName])}
onSuggestionsFetchRequested={() => {}}
/>
Expand All @@ -160,7 +167,7 @@ const Tags = ({

return (
<>
<style>{css}</style>
<style>{css(theme)}</style>
<Field.Root
name={name}
id={name}
Expand All @@ -176,7 +183,7 @@ const Tags = ({
ref={inputEle}
>
<Field.Label action={labelAction}>
{intlLabel && formatMessage({ id: intlLabel })}
{(intlLabel && formatMessage({ id: intlLabel })) || name}
</Field.Label>
<Flex direction="column">
<TagsInput
Expand Down
26 changes: 14 additions & 12 deletions admin/src/components/styles/global.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
export const css = `
export const css = (theme: "light" | "dark") => `
:root {
--primary: rgb(151, 54, 232);
--secondary: rgb(255, 255, 255);
--primary: ${theme === "light" ? "#4945ff" : "#7b79ff"};
--secondary: ${theme === "light" ? "#FFFFFF" : "#212134"};
--border: ${theme === "light" ? "#e0e0e0" : "#4a4a6a"};
--background: ${theme === "light" ? "#F7FAFC" : "#212134"};
--text: ${theme === "light" ? "#4A5568" : "#fff"};
}

.react-tagsinput {
width: 100%;
background-color: var(--secondary);
border: 1px solid #ccc;
background-color: var(--background);
border: 1px solid var(--border);
border-radius: 4px;
overflow: hidden;
padding-left: 5px;
Expand All @@ -19,10 +22,9 @@ export const css = `
}

.react-tagsinput-tag {
background-color: var(--primary);
background-color: var(--tag-background);
border-radius: 2px;
border: 1px solid var(--primary);
color: var(--secondary);
color: #fff;
display: inline-block;
font-family: sans-serif;
font-size: 13px;
Expand All @@ -44,7 +46,7 @@ export const css = `
.react-tagsinput-input {
background: transparent;
border: 0;
color: #777;
color: var(--text);
font-family: sans-serif;
font-size: 13px;
font-weight: 400;
Expand Down Expand Up @@ -73,11 +75,11 @@ export const css = `
margin: 0;
padding: 0;
list-style-type: none;
background-color: #fff;
background-color: var(--background);
}

.react-autosuggest__suggestions-container--open {
border: 1px solid #aaa;
border: 1px solid var(--primary);
}

.react-autosuggest__suggestion {
Expand All @@ -92,6 +94,6 @@ export const css = `

.react-autosuggest__suggestion--highlighted,
.react-autosuggest__suggestion--focused {
background-color: #ccc;
background-color: var(--primary);
}
`;
Loading