1
0
Fork 0
freesewing/sites/shared/components/workbench/layout/print/settings.mjs

130 lines
4.2 KiB
JavaScript
Raw Normal View History

import { PageSizePicker } from './pagesize-picker.mjs'
2023-02-05 16:30:12 +01:00
import { PageOrientationPicker } from './orientation-picker.mjs'
import { PrintIcon, RightIcon, ClearIcon, ExportIcon } from 'shared/components/icons.mjs'
2022-06-28 02:02:51 -05:00
import { useTranslation } from 'next-i18next'
import { ShowButtonsToggle } from '../draft/buttons.mjs'
2022-02-20 18:46:21 +01:00
export const PrintLayoutSettings = (props) => {
2022-11-14 16:53:31 -06:00
const { t } = useTranslation(['workbench'])
2022-11-14 14:02:11 -06:00
let pages = props.draft?.setStores[0].get('pages')
if (!pages) return null
const { cols, rows, count } = pages
2022-02-20 18:46:21 +01:00
const setMargin = (evt) => {
2022-11-14 14:02:11 -06:00
props.updateGist(
['_state', 'layout', 'forPrinting', 'page', 'margin'],
parseInt(evt.target.value)
)
}
2022-08-23 11:08:40 -05:00
const setCoverPage = () => {
2022-11-14 14:02:11 -06:00
props.updateGist(
['_state', 'layout', 'forPrinting', 'page', 'coverPage'],
!props.layoutSettings.coverPage
)
2022-08-23 11:08:40 -05:00
}
2023-03-15 12:48:46 -05:00
const setCutlist = () => {
props.updateGist(
['_state', 'layout', 'forPrinting', 'page', 'cutlist'],
!props.layoutSettings.cutlist
)
}
2022-02-20 18:46:21 +01:00
return (
2022-11-14 14:02:11 -06:00
<div>
<div
className="flex flex-row justify-between
mb-2"
>
<div className="flex gap-4">
<PageSizePicker {...props} />
2023-02-05 16:30:12 +01:00
<PageOrientationPicker {...props} />
<button
key="export"
onClick={props.exportIt}
2022-08-23 11:08:40 -05:00
className="btn btn-primary btn-outline"
disabled={count === 0}
2022-11-14 14:02:11 -06:00
aria-disabled={count === 0}
>
<ExportIcon className="h-6 w-6 mr-2" />
2023-03-15 12:48:46 -05:00
{`${t('export')} PDF`}
</button>
2023-03-15 12:48:46 -05:00
</div>
<div className="flex gap-4">
<ShowButtonsToggle
gist={props.gist}
updateGist={props.updateGist}
layoutSetType="forPrinting"
></ShowButtonsToggle>
<button
key="reset"
onClick={() => props.unsetGist(['layouts', 'printingLayout'])}
2022-11-14 14:02:11 -06:00
className="btn btn-primary btn-outline"
>
<ClearIcon className="h-6 w-6 mr-2" />
{t('reset')}
</button>
</div>
</div>
2022-08-23 11:08:40 -05:00
<div className="flex flex-row justify-between">
<div className="flex flex-row">
2023-03-15 12:48:46 -05:00
<label htmlFor="pageMargin" className="label">
<span className="">{t('pageMargin')}</span>
2022-08-23 11:08:40 -05:00
<input
type="range"
max={50}
min={0}
step={1}
onChange={setMargin}
value={props.layoutSettings.margin}
className="range range-sm mx-2"
name="pageMargin"
/>
<div className="text-center">
2022-11-14 14:02:11 -06:00
<span className="text-secondary">{props.layoutSettings.margin}mm</span>
2022-08-23 11:08:40 -05:00
</div>
<button
title={t('reset')}
className="btn btn-ghost btn-xs text-accent mx-2"
disabled={props.layoutSettings.margin == 10}
2022-11-14 14:02:11 -06:00
onClick={() => setMargin({ target: { value: 10 } })}
2022-08-23 11:08:40 -05:00
>
<ClearIcon />
</button>
</label>
<label htmlFor="coverPage" className="label">
<span className="mr-2">{t('coverPage')}</span>
2022-11-14 14:02:11 -06:00
<input
type="checkbox"
className="toggle toggle-primary"
checked={props.layoutSettings.coverPage}
onChange={setCoverPage}
/>
2022-08-23 11:08:40 -05:00
</label>
2023-03-15 12:48:46 -05:00
<label htmlFor="cutlist" className="label">
<span className="mr-2">{t('cutlist')}</span>
<input
type="checkbox"
className="toggle toggle-primary"
checked={props.layoutSettings.cutlist}
onChange={setCutlist}
/>
</label>
2022-08-23 11:08:40 -05:00
</div>
<div className="flex flex-row font-bold items-center px-0 text-xl">
<PrintIcon />
<span className="ml-2">{count}</span>
<span className="mx-6 opacity-50">|</span>
<RightIcon />
<span className="ml-2">{cols}</span>
<span className="mx-6 opacity-50">|</span>
2022-11-14 14:02:11 -06:00
<div className="rotate-90">
<RightIcon />
</div>
<span className="text-xl ml-2">{rows}</span>
</div>
</div>
2022-02-20 18:46:21 +01:00
</div>
)
}