Skip to content

Commit

Permalink
Merge pull request #21 from ftonato/feat/support-darktheme-input
Browse files Browse the repository at this point in the history
feat: adding dark-theme support for input
  • Loading branch information
Adi-ty authored Oct 4, 2023
2 parents c2b552b + e6ca2d6 commit 3cdab4e
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 103 deletions.
2 changes: 1 addition & 1 deletion components/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function ThemeToggle() {

):(
<svg width="27" height="27" viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8.54406 0.98184L8.24618 0.941586C8.03275 0.917676 7.90692 1.1655 8.02936 1.34194C8.17013 1.54479 8.29981 1.75592 8.41754 1.97445C8.91878 2.90485 9.20322 3.96932 9.20322 5.10022C9.20322 8.37201 6.82247 11.0878 3.69887 11.6097C3.45736 11.65 3.20988 11.6772 2.96008 11.6906C2.74563 11.702 2.62729 11.9535 2.77721 12.1072C2.84551 12.1773 2.91535 12.2458 2.98667 12.3128L3.05883 12.3795L3.31883 12.6045L3.50684 12.7532L3.62796 12.8433L3.81491 12.9742L3.99079 13.089C4.11175 13.1651 4.23536 13.2375 4.36157 13.3059L4.62496 13.4412L4.88553 13.5607L5.18837 13.6828L5.43169 13.7686C5.56564 13.8128 5.70149 13.8529 5.83857 13.8885C5.94262 13.9155 6.04767 13.9401 6.15405 13.9622C6.27993 13.9883 6.40713 14.0109 6.53544 14.0298L6.85241 14.0685L7.11934 14.0892C7.24637 14.0965 7.37436 14.1002 7.50322 14.1002C11.1483 14.1002 14.1032 11.1453 14.1032 7.50023C14.1032 7.25044 14.0893 7.00389 14.0623 6.76131L14.0255 6.48407C13.991 6.26083 13.9453 6.04129 13.8891 5.82642C13.8213 5.56709 13.7382 5.31398 13.6409 5.06881L13.5279 4.80132L13.4507 4.63542L13.3766 4.48666C13.2178 4.17773 13.0353 3.88295 12.8312 3.60423L12.6782 3.40352L12.4793 3.16432L12.3157 2.98361L12.1961 2.85951L12.0355 2.70246L11.8134 2.50184L11.4925 2.24191L11.2483 2.06498L10.9562 1.87446L10.6346 1.68894L10.3073 1.52378L10.1938 1.47176L9.95488 1.3706L9.67791 1.2669L9.42566 1.1846L9.10075 1.09489L8.83599 1.03486L8.54406 0.98184ZM10.4032 5.30023C10.4032 4.27588 10.2002 3.29829 9.83244 2.40604C11.7623 3.28995 13.1032 5.23862 13.1032 7.50023C13.1032 10.593 10.596 13.1002 7.50322 13.1002C6.63646 13.1002 5.81597 12.9036 5.08355 12.5522C6.5419 12.0941 7.81081 11.2082 8.74322 10.0416C8.87963 10.2284 9.10028 10.3497 9.34928 10.3497C9.76349 10.3497 10.0993 10.0139 10.0993 9.59971C10.0993 9.24256 9.84965 8.94373 9.51535 8.86816C9.57741 8.75165 9.63653 8.63334 9.6926 8.51332C9.88358 8.63163 10.1088 8.69993 10.35 8.69993C11.0403 8.69993 11.6 8.14028 11.6 7.44993C11.6 6.75976 11.0406 6.20024 10.3505 6.19993C10.3853 5.90487 10.4032 5.60464 10.4032 5.30023Z" fill="currentColor" fill-rule="evenodd" clip-rule="evenodd"/>
<path d="M8.54406 0.98184L8.24618 0.941586C8.03275 0.917676 7.90692 1.1655 8.02936 1.34194C8.17013 1.54479 8.29981 1.75592 8.41754 1.97445C8.91878 2.90485 9.20322 3.96932 9.20322 5.10022C9.20322 8.37201 6.82247 11.0878 3.69887 11.6097C3.45736 11.65 3.20988 11.6772 2.96008 11.6906C2.74563 11.702 2.62729 11.9535 2.77721 12.1072C2.84551 12.1773 2.91535 12.2458 2.98667 12.3128L3.05883 12.3795L3.31883 12.6045L3.50684 12.7532L3.62796 12.8433L3.81491 12.9742L3.99079 13.089C4.11175 13.1651 4.23536 13.2375 4.36157 13.3059L4.62496 13.4412L4.88553 13.5607L5.18837 13.6828L5.43169 13.7686C5.56564 13.8128 5.70149 13.8529 5.83857 13.8885C5.94262 13.9155 6.04767 13.9401 6.15405 13.9622C6.27993 13.9883 6.40713 14.0109 6.53544 14.0298L6.85241 14.0685L7.11934 14.0892C7.24637 14.0965 7.37436 14.1002 7.50322 14.1002C11.1483 14.1002 14.1032 11.1453 14.1032 7.50023C14.1032 7.25044 14.0893 7.00389 14.0623 6.76131L14.0255 6.48407C13.991 6.26083 13.9453 6.04129 13.8891 5.82642C13.8213 5.56709 13.7382 5.31398 13.6409 5.06881L13.5279 4.80132L13.4507 4.63542L13.3766 4.48666C13.2178 4.17773 13.0353 3.88295 12.8312 3.60423L12.6782 3.40352L12.4793 3.16432L12.3157 2.98361L12.1961 2.85951L12.0355 2.70246L11.8134 2.50184L11.4925 2.24191L11.2483 2.06498L10.9562 1.87446L10.6346 1.68894L10.3073 1.52378L10.1938 1.47176L9.95488 1.3706L9.67791 1.2669L9.42566 1.1846L9.10075 1.09489L8.83599 1.03486L8.54406 0.98184ZM10.4032 5.30023C10.4032 4.27588 10.2002 3.29829 9.83244 2.40604C11.7623 3.28995 13.1032 5.23862 13.1032 7.50023C13.1032 10.593 10.596 13.1002 7.50322 13.1002C6.63646 13.1002 5.81597 12.9036 5.08355 12.5522C6.5419 12.0941 7.81081 11.2082 8.74322 10.0416C8.87963 10.2284 9.10028 10.3497 9.34928 10.3497C9.76349 10.3497 10.0993 10.0139 10.0993 9.59971C10.0993 9.24256 9.84965 8.94373 9.51535 8.86816C9.57741 8.75165 9.63653 8.63334 9.6926 8.51332C9.88358 8.63163 10.1088 8.69993 10.35 8.69993C11.0403 8.69993 11.6 8.14028 11.6 7.44993C11.6 6.75976 11.0406 6.20024 10.3505 6.19993C10.3853 5.90487 10.4032 5.60464 10.4032 5.30023Z" fill="currentColor" fillRule="evenodd" clipRule="evenodd"/>
</svg>


Expand Down
216 changes: 115 additions & 101 deletions components/prompt-form.tsx
Original file line number Diff line number Diff line change
@@ -1,122 +1,136 @@
import React from "react";
import * as Form from "@radix-ui/react-form";
import { styled } from "@stitches/react";
import React from 'react';
import { useTheme } from 'next-themes';
import * as Form from '@radix-ui/react-form';
import { styled } from '@stitches/react';

type Props = {
onSubmit: (prompt: string) => void;
isGenerating: boolean;
onSubmit: (prompt: string) => void;
isGenerating: boolean;
};

type ThemeVariants = 'dark' | 'light';

export const PromptForm: React.FC<Props> = ({ onSubmit, isGenerating }) => {
const handleSubmit: React.FormEventHandler<HTMLFormElement> = (e) => {
e.preventDefault();

const prompt = (e.target as HTMLFormElement | undefined)?.prompt
?.value as string;
onSubmit(prompt);
};
return (
<FormRoot onSubmit={handleSubmit}>
<FormField name="email">
<Flex
css={{
alignItems: "baseline",
justifyContent: "space-between",
}}
>
<FormLabel>Prompt</FormLabel>
<FormMessage match="valueMissing">
Please enter a prompt
</FormMessage>
<FormMessage match="typeMismatch">
Please enter a valid prompt
</FormMessage>
</Flex>
<Form.Control asChild>
<Input
type="text"
name="prompt"
required
placeholder="Enter a prompt like 'a painting of a cat'"
/>
</Form.Control>
</FormField>
<Form.Submit asChild>
<Button css={{ marginTop: 10 }} disabled={isGenerating}>
{isGenerating ? "Generating.." : "Start Generating"}
</Button>
</Form.Submit>
</FormRoot>
);
const { theme, resolvedTheme } = useTheme();
const currentTheme: ThemeVariants = (theme || resolvedTheme || 'light') as ThemeVariants;

const handleSubmit: React.FormEventHandler<HTMLFormElement> = (e) => {
e.preventDefault();

const prompt = (e.target as HTMLFormElement | undefined)?.prompt?.value as string;
onSubmit(prompt);
};

return (
<StyledFormRoot onSubmit={handleSubmit}>
<StyledFormField name="email">
<StyledFlex css={{ alignItems: 'baseline', justifyContent: 'space-between' }}>
<StyledFormLabel>Prompt</StyledFormLabel>
<StyledFormMessage match="valueMissing">Please enter a prompt</StyledFormMessage>
<StyledFormMessage match="typeMismatch">Please enter a valid prompt</StyledFormMessage>
</StyledFlex>
<Form.Control asChild>
<StyledInput
type="text"
name="prompt"
required
placeholder="Enter a prompt like 'a painting of a cat'"
autoComplete="off"
theme={currentTheme}
/>
</Form.Control>
</StyledFormField>
<Form.Submit asChild>
<StyledButton css={{ marginTop: 10 }} disabled={isGenerating}>
{isGenerating ? 'Generating..' : 'Start Generating'}
</StyledButton>
</Form.Submit>
</StyledFormRoot>
);
};

const FormRoot = styled(Form.Root, {});
const StyledFormRoot = styled(Form.Root, {});

const FormField = styled(Form.Field, {
display: "grid",
marginBottom: 10,
const StyledFormField = styled(Form.Field, {
display: 'grid',
marginBottom: 10,
});

const FormLabel = styled(Form.Label, {
fontSize: 15,
fontWeight: 500,
lineHeight: "35px",
color: "$foreground",
const StyledFormLabel = styled(Form.Label, {
fontSize: 15,
fontWeight: 500,
lineHeight: '35px',
color: '$foreground',
});

const FormMessage = styled(Form.Message, {
fontSize: 13,
color: "$red600",
opacity: 0.8,
const StyledFormMessage = styled(Form.Message, {
fontSize: 13,
color: '$red600',
opacity: 0.8,
});

const Flex = styled("div", { display: "flex" });
const StyledFlex = styled('div', { display: 'flex' });

const inputStyles = {
all: "unset",
boxSizing: "border-box",
width: "100%",
display: "inline-flex",
alignItems: "center",
justifyContent: "center",
borderRadius: 4,

fontSize: 15,
color: "black",
backgroundColor: "$gray300",
boxShadow: `0 0 0 1px $gray400`,
"&:hover": { boxShadow: `0 0 0 1px $gray600` },
"&:focus": { boxShadow: `0 0 0 2px $purple600` },
"&::selection": { backgroundColor: "$gray600", color: "white" },
all: 'unset',
boxSizing: 'border-box',
width: '100%',
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
borderRadius: 4,

fontSize: 15,
color: 'black',
backgroundColor: '$gray300',
boxShadow: '0 0 0 1px $gray400',
'&:hover': { boxShadow: '0 0 0 1px $gray600' },
'&:focus': { boxShadow: '0 0 0 2px $purple600' },
'&::selection': { backgroundColor: '$gray600', color: 'white' },
};

const Input = styled("input", {
...inputStyles,
height: 35,
lineHeight: 1,
padding: "0 10px",
const StyledInput = styled('input', {
...inputStyles,
height: 35,
lineHeight: 1,
padding: '0 10px',
variants: {
theme: {
dark: {
backgroundColor: '$gray600',
color: 'white',
'&::placeholder': {
color: 'white',
},
},
light: {
backgroundColor: '$gray300',
},
},
},
});

const Button = styled("button", {
all: "unset",
boxSizing: "border-box",
display: "inline-flex",
alignItems: "center",
justifyContent: "center",
borderRadius: 4,
padding: "0 15px",
fontSize: 15,
lineHeight: 1,
fontWeight: 500,
height: 35,
width: "100%",

"&:disabled": {
opacity: 0.5,
},
backgroundColor: "$purple500",
color: "white",
boxShadow: `0 2px 10px $gray400`,
"&:not(:disabled):hover": { backgroundColor: "$purple600" },
"&:not(:disabled):focus": { boxShadow: `0 0 0 2px black` },
const StyledButton = styled('button', {
all: 'unset',
boxSizing: 'border-box',
display: 'inline-flex',
alignItems: 'center',
justifyContent: 'center',
borderRadius: 4,
padding: '0 15px',
fontSize: 15,
lineHeight: 1,
fontWeight: 500,
height: 35,
width: '100%',
cursor: 'pointer',

'&:disabled': {
opacity: 0.5,
},
backgroundColor: '$purple500',
color: 'white',
boxShadow: '0 2px 10px $gray400',
'&:not(:disabled):hover': { backgroundColor: '$purple600' },
'&:not(:disabled):focus': { boxShadow: '0 0 0 2px black' },
});
2 changes: 1 addition & 1 deletion stitches.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const {
colors: {
hiContrast: 'hsl(206,10%,5%)',
loContrast: 'white',
background:"white",
background: 'white',
gray100: 'hsl(206,22%,99%)',
gray200: 'hsl(206,12%,97%)',
gray300: 'hsl(206,11%,92%)',
Expand Down

0 comments on commit 3cdab4e

Please sign in to comment.