1
0
Fork 0
freesewing/sites/shared/components/workbench/sample.js

48 lines
1.3 KiB
JavaScript
Raw Normal View History

import SvgWrapper from './draft/svg-wrapper'
import Error from './draft/error.js'
2022-09-06 17:46:51 +02:00
import { svgattrPlugin } from '@freesewing/plugin-svgattr'
2022-02-13 15:45:27 +01:00
import { useTranslation } from 'next-i18next'
const LabSample = ({ gist, draft, updateGist, unsetGist, showInfo, app, feedback }) => {
2022-09-06 17:46:51 +02:00
2022-02-13 15:45:27 +01:00
const { t } = useTranslation(['workbench'])
let svg
let title = ''
let patternProps
const errors = []
2022-02-13 15:45:27 +01:00
if (gist.sample) {
try {
draft.use(svgattrPlugin, {
2022-02-19 17:01:28 +01:00
class: 'freesewing pattern max-h-screen'
2022-02-13 15:45:27 +01:00
})
draft = draft.sample()
// Render as React
patternProps = draft.getRenderProps()
for (const logs of patternProps.logs) errors.push(...logs.error)
2022-02-13 15:45:27 +01:00
}
catch(err) {
console.log(err)
}
if (gist.sample.type === 'option') {
title = t('testThing', {
thing: ' : ' + t('option') + ' : ' + gist.sample.option
})
}
}
return (
<>
<h2>{title}</h2>
{!patternProps || errors.length > 0 ? (
<Error {...{ draft, patternProps, updateGist }} />
) : null}
<SvgWrapper
{...{ draft, patternProps, gist, updateGist, unsetGist, showInfo, app, feedback }}
/>
2022-02-19 17:01:28 +01:00
<div className="freesewing pattern" dangerouslySetInnerHTML={{__html: svg}} />
2022-02-13 15:45:27 +01:00
</>
)
}
export default LabSample