2021-12-24 17:13:48 +01:00
|
|
|
import React, { useState } from 'react'
|
2022-09-22 09:05:20 +02:00
|
|
|
import { Examples } from '@freesewing/examples'
|
|
|
|
import { Rendertest } from '@freesewing/rendertest'
|
|
|
|
import { Tutorial } from '@freesewing/tutorial'
|
|
|
|
import Svg from '../../workbench/draft/svg'
|
|
|
|
import Defs from '../../workbench/draft/defs'
|
|
|
|
import Stack from '../../workbench/draft/stack'
|
2022-09-22 14:17:29 +02:00
|
|
|
import { useGist } from 'shared/hooks/useGist'
|
2022-09-22 09:05:20 +02:00
|
|
|
|
|
|
|
export const examplePatterns = {
|
|
|
|
examples: Examples,
|
|
|
|
//rendertest: Rendertest,
|
|
|
|
//tutorial: Tutorial,
|
|
|
|
}
|
|
|
|
|
2022-09-22 14:17:29 +02:00
|
|
|
const Example = ({ app, part, pattern='examples', xray=false }) => {
|
2022-09-22 09:05:20 +02:00
|
|
|
const Pattern = examplePatterns[pattern]
|
2022-09-22 14:17:29 +02:00
|
|
|
// State for gist
|
|
|
|
const { gist, setGist, unsetGist, updateGist, gistReady, undoGist, resetGist } = useGist(
|
|
|
|
'example-mdx',
|
|
|
|
app
|
|
|
|
)
|
|
|
|
|
2022-09-22 10:09:46 +02:00
|
|
|
if (xray) {
|
2022-09-22 14:17:29 +02:00
|
|
|
gist._state.xray = { enabled: true }
|
|
|
|
gist.margin = 20
|
2022-09-22 10:09:46 +02:00
|
|
|
}
|
2022-09-22 14:17:29 +02:00
|
|
|
if (part !== '') gist.only = [ "examples."+part]
|
|
|
|
const draft = new Pattern(gist)
|
2022-09-22 10:09:46 +02:00
|
|
|
const patternProps = draft.draft().getRenderProps()
|
2022-09-22 09:05:20 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Svg {...patternProps} embed={true}>
|
|
|
|
<Defs {...patternProps} />
|
|
|
|
<style>{`:root { --pattern-scale: 1} ${patternProps.svg.style}`}</style>
|
|
|
|
<g>
|
|
|
|
{Object.keys(patternProps.stacks).map((stackName) => (
|
2022-09-22 14:17:29 +02:00
|
|
|
<Stack {...{ app, gist, updateGist, unsetGist, patternProps }}
|
|
|
|
showInfo={app.setPopup}
|
2022-09-22 09:05:20 +02:00
|
|
|
key={stackName}
|
|
|
|
stackName={stackName}
|
|
|
|
stack={patternProps.stacks[stackName]}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</g>
|
|
|
|
</Svg>
|
|
|
|
)
|
|
|
|
}
|
2021-12-24 17:13:48 +01:00
|
|
|
|
2022-09-22 09:05:20 +02:00
|
|
|
export default Example
|