forked from mantinedev/mantine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[@mantine/demos] Migrate Demo components from @mantine/ds
- Loading branch information
Showing
28 changed files
with
695 additions
and
21 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
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
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
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
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,13 +1,20 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"include": ["src", "../configuration/types", "../gallery/src"], | ||
"exclude": ["node_modules"], | ||
"compilerOptions": { | ||
"paths": { | ||
"@docs/demos": ["./docs/src/demos"], | ||
"@mantine/*": ["src/mantine-*/src"], | ||
"@demos/*": ["src/mantine-*/src/demos"], | ||
"@gallery/*": ["../gallery/src/gallery"] | ||
} | ||
} | ||
"target": "es5", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": false, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"baseUrl": "." | ||
}, | ||
"exclude": ["node_modules"], | ||
"include": ["./src/**/*"] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import { Container } from '@mantine/core'; | ||
import { Demo } from './components/Demo/Demo'; | ||
|
||
export function attachDemos(stories: any, demos: Record<string, MantineDemo>) { | ||
Object.keys(demos).forEach((key) => { | ||
stories.add(key, () => ( | ||
<Container sx={{ paddingTop: 40, paddingBottom: 40 }} size={820}> | ||
<Demo data={demos[key]} /> | ||
</Container> | ||
)); | ||
}); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/mantine-demos/src/components/Demo/CodeDemo/CodeDemo.styles.ts
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,42 @@ | ||
import { createStyles, MantineTheme } from '@mantine/core'; | ||
|
||
export default createStyles((theme: MantineTheme) => ({ | ||
demo: { | ||
maxWidth: '100%', | ||
border: `1px solid ${ | ||
theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[1] | ||
}`, | ||
position: 'relative', | ||
|
||
'&:not(:only-child)': { | ||
borderBottom: 0, | ||
borderBottomRightRadius: 0, | ||
borderBottomLeftRadius: 0, | ||
}, | ||
}, | ||
|
||
prism: { | ||
borderBottomRightRadius: theme.radius.sm, | ||
borderBottomLeftRadius: theme.radius.sm, | ||
marginTop: 0, | ||
border: `1px solid ${ | ||
theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[1] | ||
}`, | ||
}, | ||
|
||
code: { | ||
borderTopRightRadius: 0, | ||
borderTopLeftRadius: 0, | ||
}, | ||
|
||
controls: { | ||
position: 'absolute', | ||
bottom: theme.spacing.xs - 1, | ||
right: theme.spacing.xs - 1, | ||
}, | ||
|
||
withToggle: { | ||
paddingRight: 50, | ||
minHeight: 80, | ||
}, | ||
})); |
84 changes: 84 additions & 0 deletions
84
src/mantine-demos/src/components/Demo/CodeDemo/CodeDemo.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,84 @@ | ||
import React, { useState } from 'react'; | ||
import { Language } from 'prism-react-renderer'; | ||
import { CodeIcon } from '@modulz/radix-icons'; | ||
import { useMantineTheme, Paper, Group, ActionIcon, Tooltip } from '@mantine/core'; | ||
import { Prism } from '@mantine/prism'; | ||
import useStyles from './CodeDemo.styles'; | ||
|
||
interface CodeDemoProps { | ||
code?: string; | ||
language?: Language; | ||
demoBackground?: string; | ||
demoBorder?: boolean; | ||
children?: React.ReactNode; | ||
toggle?: boolean; | ||
inline?: boolean; | ||
spacing?: boolean; | ||
zIndex?: number; | ||
} | ||
|
||
export default function CodeDemo({ | ||
code, | ||
language, | ||
children, | ||
demoBackground, | ||
demoBorder = true, | ||
toggle = false, | ||
inline = false, | ||
spacing = true, | ||
zIndex = 3, | ||
}: CodeDemoProps) { | ||
const { classes, cx } = useStyles(); | ||
const [visible, setVisible] = useState(!toggle); | ||
const theme = useMantineTheme(); | ||
|
||
if (inline) { | ||
return <div>{children}</div>; | ||
} | ||
|
||
return ( | ||
<div style={{ marginBottom: theme.spacing.xl, marginTop: theme.spacing.md }}> | ||
<Paper | ||
padding={spacing ? 'md' : 0} | ||
className={cx(classes.demo, { [classes.withToggle]: toggle })} | ||
style={{ | ||
backgroundColor: | ||
demoBackground || (theme.colorScheme === 'dark' ? theme.colors.dark[7] : theme.white), | ||
borderColor: demoBorder ? undefined : 'transparent', | ||
zIndex, | ||
}} | ||
> | ||
{children} | ||
|
||
{!!code && toggle && ( | ||
<Group position="center" direction="column" spacing={5} className={classes.controls}> | ||
<Tooltip | ||
label={`${visible ? 'Hide' : 'Show'} code`} | ||
position="left" | ||
placement="center" | ||
transition="fade" | ||
withArrow | ||
arrowSize={4} | ||
gutter={8} | ||
positionDependencies={[visible]} | ||
> | ||
<ActionIcon | ||
variant="hover" | ||
onClick={() => setVisible((v) => !v)} | ||
aria-label="Toggle code" | ||
> | ||
<CodeIcon /> | ||
</ActionIcon> | ||
</Tooltip> | ||
</Group> | ||
)} | ||
</Paper> | ||
|
||
{code && visible && ( | ||
<Prism language={language} className={classes.prism} classNames={{ code: classes.code }}> | ||
{code} | ||
</Prism> | ||
)} | ||
</div> | ||
); | ||
} |
66 changes: 66 additions & 0 deletions
66
src/mantine-demos/src/components/Demo/Configurator/Configurator.styles.ts
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,66 @@ | ||
import { createStyles, MantineTheme } from '@mantine/core'; | ||
|
||
const BREAKPOINT = 885; | ||
|
||
export default createStyles((theme: MantineTheme) => ({ | ||
configurator: { | ||
display: 'flex', | ||
maxWidth: '100%', | ||
border: `1px solid ${ | ||
theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[1] | ||
}`, | ||
overflow: 'hidden', | ||
borderTopLeftRadius: theme.radius.sm, | ||
borderTopRightRadius: theme.radius.sm, | ||
borderBottom: 0, | ||
|
||
[`@media (max-width: ${BREAKPOINT}px)`]: { | ||
flexDirection: 'column', | ||
}, | ||
}, | ||
|
||
noCode: { | ||
borderRadius: theme.radius.sm, | ||
borderBottom: `1px solid ${ | ||
theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[1] | ||
}`, | ||
}, | ||
|
||
preview: { | ||
flex: 1, | ||
padding: theme.spacing.md, | ||
display: 'flex', | ||
flexDirection: 'column', | ||
}, | ||
|
||
controls: { | ||
boxSizing: 'border-box', | ||
width: 250, | ||
padding: theme.spacing.md, | ||
borderLeft: `1px solid ${ | ||
theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[1] | ||
}`, | ||
|
||
[`@media (max-width: ${BREAKPOINT}px)`]: { | ||
width: '100%', | ||
borderLeft: 0, | ||
borderTop: `1px solid ${ | ||
theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[1] | ||
}`, | ||
}, | ||
}, | ||
|
||
prism: { | ||
borderBottomRightRadius: theme.radius.sm, | ||
borderBottomLeftRadius: theme.radius.sm, | ||
marginTop: 0, | ||
border: `1px solid ${ | ||
theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[1] | ||
}`, | ||
}, | ||
|
||
code: { | ||
borderTopRightRadius: 0, | ||
borderTopLeftRadius: 0, | ||
}, | ||
})); |
Oops, something went wrong.