feat(lab): Added tests/sampling
This commit is contained in:
parent
a8e453d2de
commit
a706e3cac2
9 changed files with 127 additions and 149 deletions
|
@ -4,7 +4,7 @@ import Link from 'next/link'
|
||||||
import { useTranslation } from 'next-i18next'
|
import { useTranslation } from 'next-i18next'
|
||||||
|
|
||||||
const PatternPicker = ({ app }) => {
|
const PatternPicker = ({ app }) => {
|
||||||
const { t } = useTranslation(['app'])
|
const { t } = useTranslation(['common'])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="dropdown">
|
<div className="dropdown">
|
||||||
|
|
|
@ -3,7 +3,7 @@ module.exports = {
|
||||||
i18n: {
|
i18n: {
|
||||||
defaultLocale: 'en',
|
defaultLocale: 'en',
|
||||||
locales: ['en', 'de', 'es', 'fr', 'nl'],
|
locales: ['en', 'de', 'es', 'fr', 'nl'],
|
||||||
defaultNS: 'app',
|
defaultNS: 'common',
|
||||||
},
|
},
|
||||||
interpolation: {
|
interpolation: {
|
||||||
prefix: '{',
|
prefix: '{',
|
||||||
|
|
|
@ -3,7 +3,7 @@ import ThemeIcon from 'shared/components/icons/theme.js'
|
||||||
import { useTranslation } from 'next-i18next'
|
import { useTranslation } from 'next-i18next'
|
||||||
|
|
||||||
const ThemePicker = ({ app, className }) => {
|
const ThemePicker = ({ app, className }) => {
|
||||||
const { t } = useTranslation(['app'])
|
const { t } = useTranslation(['themes'])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`dropdown ${className}`}>
|
<div className={`dropdown ${className}`}>
|
||||||
|
|
|
@ -17,7 +17,8 @@ const order = [
|
||||||
'info',
|
'info',
|
||||||
'debug'
|
'debug'
|
||||||
]
|
]
|
||||||
const Events = props => (
|
const Events = props => props?.draft?.events
|
||||||
|
? (
|
||||||
<div className="max-w-screen-xl m-auto">
|
<div className="max-w-screen-xl m-auto">
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<ul className="flex flex-row row-wrap">
|
<ul className="flex flex-row row-wrap">
|
||||||
|
@ -38,6 +39,6 @@ const Events = props => (
|
||||||
{order.map(type => <EventGroup type={type} events={props.draft.events[type]} />)}
|
{order.map(type => <EventGroup type={type} events={props.draft.events[type]} />)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
) : null
|
||||||
|
|
||||||
export default Events
|
export default Events
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { Ul, Details, TopSummary, TopSumTitle } from 'shared/components/workbenc
|
||||||
import { useTranslation } from 'next-i18next'
|
import { useTranslation } from 'next-i18next'
|
||||||
|
|
||||||
const DesignOptions = props => {
|
const DesignOptions = props => {
|
||||||
const { t } = useTranslation(['app'])
|
const { t } = useTranslation(['workbench'])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Details open>
|
<Details open>
|
||||||
|
|
|
@ -1,128 +1,65 @@
|
||||||
import { Chevron } from 'shared/components/navigation/primary.js'
|
import { linkClasses } from 'shared/components/navigation/primary.js'
|
||||||
import PctDegOption from 'shared/components/workbench/inputs/design-option-pct-deg'
|
import { Li, Ul, Details, Summary, Deg } from 'shared/components/workbench/menu'
|
||||||
import CountOption from 'shared/components/workbench/inputs/design-option-count'
|
|
||||||
import ListOption from 'shared/components/workbench/inputs/design-option-list'
|
|
||||||
import { formatMm, formatPercentage, optionType } from 'shared/utils.js'
|
|
||||||
import { Li, Ul, Details, Summary, SumButton, SumDiv, Deg } from 'shared/components/workbench/menu'
|
|
||||||
import { useTranslation } from 'next-i18next'
|
import { useTranslation } from 'next-i18next'
|
||||||
|
|
||||||
const values = {
|
const SumButton = props => (
|
||||||
pct: props => {
|
<button className={`
|
||||||
const val = (typeof props.gist?.options?.[props.option] === 'undefined')
|
flex flex-row
|
||||||
? props.pattern.config.options[props.option].pct/100
|
px-2
|
||||||
: props.gist.options[props.option]
|
w-full justify-between
|
||||||
return (
|
text-left
|
||||||
<span className={
|
text-base-content
|
||||||
val=== props.pattern.config.options[props.option].pct/100
|
sm:text-neutral-content
|
||||||
? 'text-secondary-focus'
|
hover:cursor-pointer
|
||||||
: 'text-accent'
|
items-center
|
||||||
}>
|
mr-4
|
||||||
{formatPercentage(val)}
|
`} onClick={props.onClick}>{props.children}</button>
|
||||||
{props.pattern.config.options[props.option]?.toAbs
|
)
|
||||||
? ' | ' +formatMm(props.pattern.config.options[props.option]?.toAbs(val, props.gist))
|
const SumDiv = (props) => (
|
||||||
: null
|
<div className={`
|
||||||
}
|
grow pl-2 border-l-2
|
||||||
</span>
|
${linkClasses}
|
||||||
)
|
hover:cursor-resize
|
||||||
},
|
hover:border-secondary
|
||||||
bool: props => {
|
sm:hover:border-secondary-focus
|
||||||
const { t } = useTranslation(['app'])
|
text-base-content sm:text-neutral-content
|
||||||
const dflt = props.pattern.config.options[props.option].bool
|
${props.active && 'border-secondary-focus'}
|
||||||
const current = props.gist?.options?.[props.option]
|
|
||||||
return (
|
|
||||||
<span className={
|
|
||||||
(dflt==current || typeof current === 'undefined')
|
|
||||||
? 'text-secondary-focus'
|
|
||||||
: 'text-accent'
|
|
||||||
}>
|
|
||||||
{props.gist?.options?.[props.option]
|
|
||||||
? t('yes')
|
|
||||||
: t('no')
|
|
||||||
}
|
|
||||||
</span>
|
|
||||||
)
|
|
||||||
},
|
|
||||||
count: props => {
|
|
||||||
const dflt = props.pattern.config.options[props.option].count
|
|
||||||
const current = props.gist?.options?.[props.option]
|
|
||||||
return (dflt==current || typeof current === 'undefined')
|
|
||||||
? <span className="text-secondary-focus">{dflt}</span>
|
|
||||||
: <span className="text-accent">{current}</span>
|
|
||||||
},
|
|
||||||
list: props => {
|
|
||||||
const dflt = props.pattern.config.options[props.option].dflt
|
|
||||||
const current = props.gist?.options?.[props.option]
|
|
||||||
const prefix = `${props.option}.o.`
|
|
||||||
return (dflt==current || typeof current === 'undefined')
|
|
||||||
? <span className="text-secondary-focus">{props.t(prefix+dflt)}</span>
|
|
||||||
: <span className="text-accent">{props.t(prefix+current)}</span>
|
|
||||||
},
|
|
||||||
deg: props => {
|
|
||||||
const dflt = props.pattern.config.options[props.option].deg
|
|
||||||
const current = props.gist?.options?.[props.option]
|
|
||||||
return (dflt==current || typeof current === 'undefined')
|
|
||||||
? <span className="text-secondary-focus">{dflt}°</span>
|
|
||||||
: <span className="text-accent">{current}°</span>
|
|
||||||
},
|
|
||||||
mm: props => {
|
|
||||||
return <p>No mm val yet</p>
|
|
||||||
},
|
|
||||||
constant: props => {
|
|
||||||
return <p>No constant val yet</p>
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
const Tmp = props => <p>not yet</p>
|
|
||||||
|
|
||||||
const inputs = {
|
|
||||||
pct: PctDegOption,
|
|
||||||
count: CountOption,
|
|
||||||
deg: props => <PctDegOption {...props} type='deg' />,
|
|
||||||
list: ListOption,
|
|
||||||
mm: <p>Mm options are not supported. Please report this.</p>,
|
|
||||||
constant: Tmp,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
`}>{props.children}</div>
|
||||||
|
)
|
||||||
|
|
||||||
const Option = props => {
|
const Option = props => {
|
||||||
const { t } = useTranslation([`o_${props.pattern.config.name}`])
|
const { t } = useTranslation([`o_${props.pattern.config.name}`, 'workbench'])
|
||||||
const type = optionType(props.pattern.config.options[props.option])
|
const active = (
|
||||||
const Input = inputs[type]
|
props.gist.sample?.type === 'option' &&
|
||||||
const Value = values[type]
|
props.gist.sample?.option === props.option
|
||||||
|
)
|
||||||
|
|
||||||
const toggleBoolean = () => {
|
return (
|
||||||
const dflt = props.pattern.config.options[props.option].bool
|
<Li>
|
||||||
const current = props.gist?.options?.[props.option]
|
<SumButton onClick={() => props.updateGist(
|
||||||
if (typeof current === 'undefined')
|
['sample'],
|
||||||
props.updateGist(['options', props.option], !dflt)
|
{
|
||||||
else props.unsetGist(['options', props.option])
|
type: 'option',
|
||||||
|
option: props.option
|
||||||
}
|
}
|
||||||
|
)}>
|
||||||
return (type === 'bool')
|
<SumDiv active={active}>
|
||||||
? (
|
<span className={`
|
||||||
<Li>
|
text-3xl inline-block p-0 leading-3 px-2
|
||||||
<SumButton onClick={toggleBoolean}>
|
${active
|
||||||
<SumDiv>
|
? 'text-secondary sm:text-secondary-focus translate-y-1 font-bold'
|
||||||
<Deg />
|
: 'translate-y-3'
|
||||||
<span>{t(`${props.option}.t`) }</span>
|
}`}
|
||||||
|
>
|
||||||
|
{active ? <span>•</span> : <span>°</span>}
|
||||||
|
</span>
|
||||||
|
<span className={active ? 'text-secondary font-bold' : ''}>
|
||||||
|
{t(`o_${props.pattern.config.name}:${props.option}.t`)}
|
||||||
|
</span>
|
||||||
</SumDiv>
|
</SumDiv>
|
||||||
<Value type={type} {...props} t={t} />
|
|
||||||
</SumButton>
|
</SumButton>
|
||||||
</Li>
|
</Li>
|
||||||
) : (
|
|
||||||
<Li>
|
|
||||||
<Details>
|
|
||||||
<Summary>
|
|
||||||
<SumDiv>
|
|
||||||
<Deg />
|
|
||||||
<span>{t(`${props.option}.t`)}</span>
|
|
||||||
</SumDiv>
|
|
||||||
<Value type={type} {...props} t={t} />
|
|
||||||
<Chevron w={6} m={3}/>
|
|
||||||
</Summary>
|
|
||||||
<Input {...props} ot={t} />
|
|
||||||
</Details>
|
|
||||||
</Li>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ const View = props => {
|
||||||
<span className={`
|
<span className={`
|
||||||
text-3xl mr-2 inline-block p-0 leading-3
|
text-3xl mr-2 inline-block p-0 leading-3
|
||||||
${entry.name === props.gist?._state?.view
|
${entry.name === props.gist?._state?.view
|
||||||
? 'text-secondary sm:text-secondary-focus translate-y-1'
|
? 'text-secondary sm:text-secondary-focus translate-y-1 font-bold'
|
||||||
: 'translate-y-3'
|
: 'translate-y-3'
|
||||||
}
|
}
|
||||||
`}>
|
`}>
|
||||||
|
|
37
packages/freesewing.shared/components/workbench/sample.js
Normal file
37
packages/freesewing.shared/components/workbench/sample.js
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
import svgattrPlugin from '@freesewing/plugin-svgattr'
|
||||||
|
import { useTranslation } from 'next-i18next'
|
||||||
|
|
||||||
|
const LabSample = ({ gist, draft }) => {
|
||||||
|
const { t } = useTranslation(['workbench'])
|
||||||
|
let svg
|
||||||
|
let title = ''
|
||||||
|
if (gist.sample) {
|
||||||
|
try {
|
||||||
|
draft.use(svgattrPlugin, {
|
||||||
|
class: 'freesewing'
|
||||||
|
})
|
||||||
|
draft.sample()
|
||||||
|
svg = draft.render()
|
||||||
|
}
|
||||||
|
catch(err) {
|
||||||
|
console.log(err)
|
||||||
|
}
|
||||||
|
if (gist.sample.type === 'option') {
|
||||||
|
title = t('testThing', {
|
||||||
|
thing: ' : ' + t('option') + ' : ' + gist.sample.option
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h2>{title}</h2>
|
||||||
|
<div
|
||||||
|
className="freesewing pattern"
|
||||||
|
dangerouslySetInnerHTML={{ __html: svg }}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LabSample
|
|
@ -11,6 +11,7 @@ import theme from 'pkgs/plugin-theme/src/index.js'
|
||||||
// Views
|
// Views
|
||||||
import Measurements from 'shared/components/workbench/measurements/index.js'
|
import Measurements from 'shared/components/workbench/measurements/index.js'
|
||||||
import LabDraft from 'shared/components/workbench/draft/index.js'
|
import LabDraft from 'shared/components/workbench/draft/index.js'
|
||||||
|
import LabSample from 'shared/components/workbench/sample.js'
|
||||||
import GistAsJson from 'shared/components/workbench/json.js'
|
import GistAsJson from 'shared/components/workbench/json.js'
|
||||||
import GistAsYaml from 'shared/components/workbench/yaml.js'
|
import GistAsYaml from 'shared/components/workbench/yaml.js'
|
||||||
import DraftEvents from 'shared/components/workbench/events.js'
|
import DraftEvents from 'shared/components/workbench/events.js'
|
||||||
|
@ -18,7 +19,7 @@ import DraftEvents from 'shared/components/workbench/events.js'
|
||||||
const views = {
|
const views = {
|
||||||
measurements: Measurements,
|
measurements: Measurements,
|
||||||
draft: LabDraft,
|
draft: LabDraft,
|
||||||
test: () => <p>TODO</p>,
|
test: LabSample,
|
||||||
export: () => <p>TODO</p>,
|
export: () => <p>TODO</p>,
|
||||||
events: DraftEvents,
|
events: DraftEvents,
|
||||||
yaml: GistAsYaml,
|
yaml: GistAsYaml,
|
||||||
|
@ -79,10 +80,12 @@ const WorkbenchWrapper = ({ app, pattern }) => {
|
||||||
|
|
||||||
// Generate the draft here so we can pass it down
|
// Generate the draft here so we can pass it down
|
||||||
let draft = false
|
let draft = false
|
||||||
if (['draft', 'events'].indexOf(gist?._state?.view) !== -1) {
|
if (['draft', 'events', 'test'].indexOf(gist?._state?.view) !== -1) {
|
||||||
draft = new pattern(gist)
|
draft = new pattern(gist)
|
||||||
if (gist?.renderer === 'svg') draft.use(theme)
|
if (gist?.renderer === 'svg') draft.use(theme)
|
||||||
try { draft.draft() }
|
try {
|
||||||
|
if (gist._state.view !== 'test') draft.draft()
|
||||||
|
}
|
||||||
catch(error) {
|
catch(error) {
|
||||||
console.log('Failed to draft pattern', error)
|
console.log('Failed to draft pattern', error)
|
||||||
return <DraftError error={error} app={app} draft={draft} at={'draft'} />
|
return <DraftError error={error} app={app} draft={draft} at={'draft'} />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue