Skip to content

Commit

Permalink
minor editings
Browse files Browse the repository at this point in the history
  • Loading branch information
serdec committed Oct 10, 2023
1 parent 49ecb82 commit 96bc348
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
16 changes: 16 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ import {
WarningAlert,
CardPrimary,
} from "@/components";
import { Dialog } from "@/components/Dialog/Dialog";

const App = () => {
const [currentTheme, setCurrentTheme] = useState<ThemeName>("dark");
const [selectedButton, setSelectedButton] = useState(0);
const [checked, setChecked] = useState(false);
const [disabled] = useState(false);
const [open, setOpen] = useState(true);

return (
<ClickUIProvider
Expand Down Expand Up @@ -267,6 +269,20 @@ const App = () => {
title="Title"
/>
<Avatar text="CH" />

<Button onClick={() => setOpen(true)}>Button</Button>
<Dialog
open={open}
onOpenChange={setOpen}
>
<Dialog.Content
title="Hello"
showClose
onClose={() => setOpen(false)}
>
<p>I'm a dialog</p>
</Dialog.Content>
</Dialog>
</ClickUIProvider>
);
};
Expand Down
11 changes: 7 additions & 4 deletions src/components/Dialog/Dialog.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ const DialogComponent = ({
showClose,
forceMount,
}: {
open: "default" | "open" | "closed";
open?: boolean;
title: string;
modal: boolean;
showClose: boolean;
forceMount?: boolean;
}) => (
<GridCenter>
<Dialog
open={open === "default" ? undefined : open === "open"}
open={open}
modal={modal}
>
<Dialog.Trigger>
Expand Down Expand Up @@ -59,7 +59,7 @@ export default {
tags: ["autodocs", "dialog"],
argTypes: {
open: {
options: ["default", "open", "closed"],
options: [true, false, undefined],
control: { type: "radio" },
},
},
Expand All @@ -68,7 +68,10 @@ export default {
export const Playground = {
args: {
title: "Example dialog title",
open: "true",
showClose: true,
open: true,
onOpenChange: () => {
console.log("ignored");
},
},
};
19 changes: 6 additions & 13 deletions src/components/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@ interface DialogTriggerProps extends RadixDialog.DialogTriggerProps {
}

const DialogTrigger = ({ children, ...props }: DialogTriggerProps) => {
return (
<>
<Trigger
asChild
{...props}
>
{children}
</Trigger>
</>
);
return <Trigger {...props}>{children}</Trigger>;
};

DialogTrigger.displayName = "DialogTrigger";
Expand Down Expand Up @@ -111,9 +102,9 @@ const CrossButton = styled(EmptyButton)`
}
`;

const CloseButton = () => (
const CloseButton = ({ onClose }: { onClose?: () => void }) => (
<RadixDialog.Close asChild>
<CrossButton>
<CrossButton onClick={onClose}>
<Icon
name="cross"
size="lg"
Expand All @@ -128,12 +119,14 @@ interface DialogContentProps extends RadixDialog.DialogContentProps {
forceMount?: true;
container?: HTMLElement | null;
children: ReactNode;
onClose?: () => void;
}

const DialogContent = ({
title,
children,
showClose,
onClose,
forceMount,
container,
}: DialogContentProps) => {
Expand All @@ -151,7 +144,7 @@ const DialogContent = ({
>
{title}
</Title>
{showClose && <CloseButton />}
{showClose && <CloseButton onClose={onClose} />}
</TitleArea>
<Spacer />
{children}
Expand Down

0 comments on commit 96bc348

Please sign in to comment.