-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Introduce an appearance demo (#4028)
* improve that thing * that thing too * remove stuff * extract appearance getter * add types * 🤷 * styling yay * save * default list box * ! * style the floating default select * finally done with styling! * eeeeh * remove relative * remove log * vertical! * better * increase card border color * props to demo * styling * message * Create many-steaks-shave.md * fixes
- Loading branch information
Showing
19 changed files
with
443 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@marigold/docs": patch | ||
"@marigold/components": patch | ||
"@marigold/theme-b2b": patch | ||
"@marigold/theme-docs": patch | ||
--- | ||
|
||
docs: Introduce an appearance demo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
docs/content/components/form/button/button-appearance.demo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { ButtonProps } from '@marigold/components'; | ||
import { Button } from '@marigold/components'; | ||
|
||
export default (props: ButtonProps) => <Button {...props}>Press me</Button>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,111 @@ | ||
export const AppearanceDemo = () => {}; | ||
import { getAppearance } from '@/lib/utils'; | ||
import { registry } from '@/registry/demos'; | ||
import { | ||
Card, | ||
FieldGroup, | ||
MarigoldProvider, | ||
OverlayContainerProvider, | ||
Select, | ||
} from '@/ui'; | ||
import type { Theme } from '@/ui'; | ||
import type { ComponentType, ReactNode } from 'react'; | ||
import { useState } from 'react'; | ||
|
||
import { useThemeSwitch } from '@/ui/ThemeSwitch'; | ||
|
||
// Props | ||
// --------------- | ||
export interface AppearanceDemoProps { | ||
component: keyof Theme['components']; | ||
disableLabelWidth?: boolean; | ||
} | ||
|
||
// Component | ||
// --------------- | ||
export const AppearanceDemo = ({ | ||
component, | ||
disableLabelWidth, | ||
}: AppearanceDemoProps) => { | ||
const name = `${component.toLowerCase()}-appearance` as keyof typeof registry; | ||
|
||
if (!registry[name]) { | ||
throw Error(`No demo with name "${name}" found in the registry.`); | ||
} | ||
|
||
const Demo: ComponentType<any> = registry[name].demo; | ||
const { current, themes } = useThemeSwitch(); | ||
const theme = themes[current]; | ||
const appearance = getAppearance(component, theme); | ||
|
||
const [selected, setSelected] = useState({ | ||
variant: 'default', | ||
size: 'default', | ||
}); | ||
|
||
const Wrapper = ({ children }: { children: ReactNode }) => | ||
current === 'core' && !disableLabelWidth ? ( | ||
<FieldGroup labelWidth="100px">{children}</FieldGroup> | ||
) : ( | ||
children | ||
); | ||
|
||
return ( | ||
<> | ||
<p> | ||
The appearance of a component can be customized using the{' '} | ||
<code>variant</code> and <code>size</code> props. These props adjust the | ||
visual style and dimensions of the component, available values are based | ||
on the active theme. | ||
</p> | ||
<Card variant="content" p={0}> | ||
<div className="absolute left-4 top-3 flex gap-2"> | ||
<Select | ||
label="Variant" | ||
variant="floating" | ||
size="small" | ||
width={36} | ||
selectedKey={selected.variant} | ||
onChange={(val: string) => | ||
setSelected({ variant: val, size: selected.size }) | ||
} | ||
> | ||
<Select.Option id="default">default</Select.Option> | ||
{appearance.variant.map(v => ( | ||
<Select.Option key={v} id={v}> | ||
{v} | ||
</Select.Option> | ||
))} | ||
</Select> | ||
<Select | ||
label="Size" | ||
variant="floating" | ||
size="small" | ||
width={32} | ||
selectedKey={selected.size} | ||
onChange={(val: string) => | ||
setSelected({ variant: selected.variant, size: val }) | ||
} | ||
> | ||
<Select.Option id="default">default</Select.Option> | ||
{appearance.size.map(v => ( | ||
<Select.Option key={v} id={v}> | ||
{v} | ||
</Select.Option> | ||
))} | ||
</Select> | ||
</div> | ||
<div data-theme={current}> | ||
<OverlayContainerProvider value="portalContainer"> | ||
<MarigoldProvider theme={theme}> | ||
<div className="not-prose flex size-full min-h-56 items-center justify-center overflow-x-auto px-4 pb-4 pt-14"> | ||
<Wrapper> | ||
<Demo {...selected} /> | ||
</Wrapper> | ||
</div> | ||
</MarigoldProvider> | ||
</OverlayContainerProvider> | ||
</div> | ||
</Card> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.