Skip to content

Commit

Permalink
website: update playground
Browse files Browse the repository at this point in the history
  • Loading branch information
gpbl committed Dec 26, 2024
1 parent 99a45a9 commit b1cbfe8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 22 deletions.
10 changes: 8 additions & 2 deletions website/src/components/BrowserWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface Props {
minHeight?: number;
url: string;
style?: CSSProperties;
styleStr?: string;
bodyStyle?: CSSProperties;
shadow?: boolean;
}
Expand All @@ -23,7 +24,8 @@ export function BrowserWindow({
minHeight,
style,
bodyStyle,
shadow = true
shadow = true,
styleStr
}: Props) {
return (
<div className={styles.browserWindow} style={{ ...style, minHeight }}>
Expand All @@ -36,7 +38,11 @@ export function BrowserWindow({
</div>

<div className={styles.browserWindowBody} style={bodyStyle}>
{shadow ? <ShadowDomWrapper>{children}</ShadowDomWrapper> : children}
{shadow ? (
<ShadowDomWrapper styleStr={styleStr}>{children}</ShadowDomWrapper>
) : (
children
)}
</div>
</div>
);
Expand Down
9 changes: 8 additions & 1 deletion website/src/components/ShadowDomWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import style from "!raw-loader!react-day-picker/src/style.css";
import { useColorMode } from "@docusaurus/theme-common";
import root from "react-shadow";

export function ShadowDomWrapper({ children }: { children: React.ReactNode }) {
export function ShadowDomWrapper({
children,
styleStr
}: {
children: React.ReactNode;
styleStr: string;
}) {
const colorMode = useColorMode();
return (
<root.div>
Expand All @@ -18,6 +24,7 @@ export function ShadowDomWrapper({ children }: { children: React.ReactNode }) {
}
`}</style>
)}
{styleStr && <style>{styleStr}</style>}
</root.div>
);
}
49 changes: 30 additions & 19 deletions website/src/pages/playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,10 @@ export default function Playground() {
locale: (props.locale as locales.Locale) ?? locales.enUS,
timeZone: props.timeZone
});
const formatFn = calendar === "Persian" ? "formatPersian" : "formatGregorian";

return (
<Layout>
<Head>
<style>
{`
.rdp-root,
[data-theme="dark"] .rdp-root {
${accentColor ? `--rdp-accent-color: ${accentColor} !important` : ""};
${backgroundAccentColor ? `--rdp-accent-background-color: ${backgroundAccentColor} !important` : ""};
${rangeMiddleColor ? `--rdp-range_middle-color: ${rangeMiddleColor} !important` : ""};
}
`}
</style>
<title>DayPicker Playground</title>
<meta
name="description"
Expand Down Expand Up @@ -577,7 +566,17 @@ export default function Playground() {
</fieldset>
</form>
<div className={styles.browserWindow}>
<BrowserWindow url="">
<BrowserWindow
url=""
styleStr={`
.rdp-root,
[data-theme="dark"] .rdp-root {
${accentColor ? `--rdp-accent-color: ${accentColor} !important` : ""};
${backgroundAccentColor ? `--rdp-accent-background-color: ${backgroundAccentColor} !important` : ""};
${rangeMiddleColor ? `--rdp-range_middle-color: ${rangeMiddleColor} !important` : ""};
}
`}
>
<DayPickerComponent
{...props}
onSelect={setSelected}
Expand All @@ -592,13 +591,17 @@ export default function Playground() {
{selected ? (
<div>
<pre>
{props.mode === "single" &&
selected &&
dateLib.format(selected as Date, "EEEE, d MMMM yyyy")}
{props.mode === "single" && selected && (
<>
{String(selected)} -{" "}
{dateLib.format(selected as Date, "EEEE, d MMMM yyyy")}
</>
)}
{props.mode === "multiple" &&
(selected as Date[] | undefined)?.map((date) => {
return (
<>
{String(date)} -{" "}
{dateLib.format(date, "EEEE, d MMMM yyyy")}
<br />
</>
Expand All @@ -607,12 +610,20 @@ export default function Playground() {
{props.mode === "range" && isDateRange(selected) && (
<>
From:{" "}
{selected.from &&
dateLib.format(selected.from, "EEEE, d MMMM yyyy")}
{selected.from && (
<>
{String(selected.from)} -{" "}
{dateLib.format(selected.from, "EEEE, d MMMM yyyy")}
</>
)}
<br />
To: {" "}
{selected.to &&
dateLib.format(selected.to, "EEEE, d MMMM yyyy")}
{selected.to && (
<>
{String(selected.to)} -{" "}
{dateLib.format(selected.to, "EEEE, d MMMM yyyy")}
</>
)}
</>
)}
</pre>
Expand Down

0 comments on commit b1cbfe8

Please sign in to comment.