Shorter label for ExportButton, longer in dropdown

This commit is contained in:
ochafik 2024-12-23 23:59:56 +00:00 • committed by Olivier Chafik
commit 7c82459e1f

View file

@ -4,42 +4,49 @@ import { ModelContext } from './contexts';
import { SplitButton } from 'primereact/splitbutton'; import { SplitButton } from 'primereact/splitbutton';
import { MenuItem } from 'primereact/menuitem'; import { MenuItem } from 'primereact/menuitem';
type ExtendedMenuItem = MenuItem & { buttonLabel: string };
export default function ExportButton({className, style}: {className?: string, style?: React.CSSProperties}) { export default function ExportButton({className, style}: {className?: string, style?: React.CSSProperties}) {
const model = useContext(ModelContext); const model = useContext(ModelContext);
if (!model) throw new Error('No model'); if (!model) throw new Error('No model');
const state = model.state; const state = model.state;
const dropdownModel: MenuItem[] = const dropdownModel: ExtendedMenuItem[] =
state.is2D ? [ state.is2D ? [
{ {
data: 'svg', data: 'svg',
label: 'SVG', buttonLabel: 'SVG',
label: 'SVG (Simple Vector Graphics)',
icon: 'pi pi-download', icon: 'pi pi-download',
command: () => model!.setFormats('svg', undefined), command: () => model!.setFormats('svg', undefined),
}, },
{ {
data: 'dxf', data: 'dxf',
label: 'DXF', buttonLabel: 'DXF',
label: 'DXF (Drawing Exchange Format)',
icon: 'pi pi-download', icon: 'pi pi-download',
command: () => model!.setFormats('dxf', undefined), command: () => model!.setFormats('dxf', undefined),
}, },
] : [ ] : [
{ {
data: 'glb', data: 'glb',
label: 'GLB (glTF)', buttonLabel: 'GLB',
icon: 'pi pi-download', label: 'GLB (binary glTF)',
icon: 'pi pi-file',
command: () => model!.setFormats(undefined, 'glb'), command: () => model!.setFormats(undefined, 'glb'),
}, },
{ {
data: 'stl', data: 'stl',
label: 'STL', buttonLabel: 'STL',
icon: 'pi pi-download', label: 'STL (binary)',
icon: 'pi pi-file',
command: () => model!.setFormats(undefined, 'stl'), command: () => model!.setFormats(undefined, 'stl'),
}, },
{ {
data: 'off', data: 'off',
label: 'OFF', buttonLabel: 'OFF',
icon: 'pi pi-download', label: 'OFF (Object File Format)',
icon: 'pi pi-file',
command: () => model!.setFormats(undefined, 'off'), command: () => model!.setFormats(undefined, 'off'),
}, },
]; ];
@ -50,7 +57,7 @@ export default function ExportButton({className, style}: {className?: string, st
return ( return (
<div className={className} style={style}> <div className={className} style={style}>
<SplitButton <SplitButton
label={selectedItem.label} label={selectedItem.buttonLabel}
disabled={!state.output || state.output.isPreview || state.rendering || state.exporting} disabled={!state.output || state.output.isPreview || state.rendering || state.exporting}
icon="pi pi-download" icon="pi pi-download"
model={dropdownModel} model={dropdownModel}