Created complete business logic system for door dimensions:
**New: lib/calculations.ts**
- calculateHoleWidth: Total wall opening needed
- calculateHoleMinWidth/MaxWidth: Dynamic limits based on config
- calculateSidePanelWidth: Side panel sizing logic
- calculateDoorLeafWidth: Individual door panel width
- validateDimensions: Real-time validation
- Constants: Frame profiles (80mm), min/max widths
**Enhanced: lib/store.ts**
- Added doorConfig: 'enkele' | 'dubbele' (single/double door)
- Added sidePanel: 'geen' | 'links' | 'rechts' | 'beide'
- Calculated fields: holeWidth, doorLeafWidth, sidePanelWidth, min/maxWidth
- Auto-recalculation on config changes
- setWidth/setHeight with automatic clamping to valid ranges
- Internal recalculate() method updates all derived values
**Redesigned: step-dimensions.tsx**
- Door configuration selector (enkele/dubbele)
- Side panel selector (geen/links/rechts/beide)
- Width slider with dynamic min/max based on configuration
- Height slider (1800-3000mm)
- Real-time input fields synced with sliders
- Summary panel showing:
- Door leaf width
- Total wall opening (hole width × height)
- Side panel width (when applicable)
- Premium tile-based UI (Dark Green/Pistachio theme)
**Added: components/ui/slider.tsx**
- Shadcn Slider component for smooth value selection
**Connected: door-3d.tsx**
- Door now uses doorLeafWidth from store (in mm, converted to meters)
- Door height from store (in mm, converted to meters)
- 3D door resizes in real-time as user drags sliders
- Maintains realistic proportions
**User Flow:**
1. User selects enkele/dubbele configuration
2. User selects side panels (if any)
3. Store calculates valid min/max widths
4. User drags width slider (clamped to valid range)
5. Store calculates door leaf width and side panel widths
6. 3D door updates instantly to show new dimensions
7. Summary shows all calculated dimensions
**Result:** Professional dimension configurator with real business logic,
automatic validation, and real-time 3D preview
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
126 lines
3.1 KiB
TypeScript
126 lines
3.1 KiB
TypeScript
import { create } from 'zustand';
|
|
import {
|
|
calculateHoleWidth,
|
|
calculateHoleMinWidth,
|
|
calculateHoleMaxWidth,
|
|
calculateSidePanelWidth,
|
|
calculateDoorLeafWidth,
|
|
type DoorConfig,
|
|
type SidePanel,
|
|
} from './calculations';
|
|
|
|
export type DoorType = 'taats' | 'scharnier' | 'paneel';
|
|
export type GridType = '3-vlak' | '4-vlak' | 'geen';
|
|
export type Finish = 'zwart' | 'brons' | 'grijs';
|
|
export type Handle = 'u-greep' | 'klink' | 'geen';
|
|
|
|
interface ConfiguratorState {
|
|
// Door configuration
|
|
doorType: DoorType;
|
|
doorConfig: DoorConfig;
|
|
sidePanel: SidePanel;
|
|
|
|
// Styling
|
|
gridType: GridType;
|
|
finish: Finish;
|
|
handle: Handle;
|
|
|
|
// Dimensions (in mm)
|
|
width: number;
|
|
height: number;
|
|
|
|
// Calculated values
|
|
holeWidth: number;
|
|
doorLeafWidth: number;
|
|
sidePanelWidth: number;
|
|
minWidth: number;
|
|
maxWidth: number;
|
|
|
|
// Actions
|
|
setDoorType: (type: DoorType) => void;
|
|
setDoorConfig: (config: DoorConfig) => void;
|
|
setSidePanel: (panel: SidePanel) => void;
|
|
setGridType: (type: GridType) => void;
|
|
setFinish: (finish: Finish) => void;
|
|
setHandle: (handle: Handle) => void;
|
|
setWidth: (width: number) => void;
|
|
setHeight: (height: number) => void;
|
|
setDimensions: (width: number, height: number) => void;
|
|
}
|
|
|
|
export const useConfiguratorStore = create<ConfiguratorState>((set, get) => ({
|
|
// Initial state
|
|
doorType: 'taats',
|
|
doorConfig: 'enkele',
|
|
sidePanel: 'geen',
|
|
gridType: '3-vlak',
|
|
finish: 'zwart',
|
|
handle: 'u-greep',
|
|
width: 1000,
|
|
height: 2400,
|
|
|
|
// Initial calculated values
|
|
holeWidth: 1160,
|
|
doorLeafWidth: 1000,
|
|
sidePanelWidth: 0,
|
|
minWidth: 860,
|
|
maxWidth: 1360,
|
|
|
|
// Actions with automatic recalculation
|
|
setDoorType: (doorType) => {
|
|
set({ doorType });
|
|
get().recalculate();
|
|
},
|
|
|
|
setDoorConfig: (doorConfig) => {
|
|
set({ doorConfig });
|
|
get().recalculate();
|
|
},
|
|
|
|
setSidePanel: (sidePanel) => {
|
|
set({ sidePanel });
|
|
get().recalculate();
|
|
},
|
|
|
|
setGridType: (gridType) => set({ gridType }),
|
|
|
|
setFinish: (finish) => set({ finish }),
|
|
|
|
setHandle: (handle) => set({ handle }),
|
|
|
|
setWidth: (width) => {
|
|
const { doorConfig, sidePanel } = get();
|
|
const minWidth = calculateHoleMinWidth(doorConfig, sidePanel);
|
|
const maxWidth = calculateHoleMaxWidth(doorConfig, sidePanel);
|
|
|
|
// Clamp width to valid range
|
|
const clampedWidth = Math.max(minWidth, Math.min(maxWidth, width));
|
|
set({ width: clampedWidth });
|
|
get().recalculate();
|
|
},
|
|
|
|
setHeight: (height) => {
|
|
// Clamp height to valid range
|
|
const clampedHeight = Math.max(1800, Math.min(3000, height));
|
|
set({ height: clampedHeight });
|
|
},
|
|
|
|
setDimensions: (width, height) => {
|
|
get().setWidth(width);
|
|
get().setHeight(height);
|
|
},
|
|
|
|
// Internal recalculation helper
|
|
recalculate: () => {
|
|
const { width, doorConfig, sidePanel } = get();
|
|
|
|
set({
|
|
holeWidth: calculateHoleWidth(width, doorConfig, sidePanel),
|
|
doorLeafWidth: calculateDoorLeafWidth(width, doorConfig, sidePanel),
|
|
sidePanelWidth: calculateSidePanelWidth(width, doorConfig, sidePanel),
|
|
minWidth: calculateHoleMinWidth(doorConfig, sidePanel),
|
|
maxWidth: calculateHoleMaxWidth(doorConfig, sidePanel),
|
|
});
|
|
},
|
|
} as ConfiguratorState));
|