MCPcopy Create free account
hub / github.com/DavidHDev/react-bits / Controls

Function Controls

src/tools/shape-magic/Controls.jsx:264–873  ·  view source on GitHub ↗
({
  shapes,
  bridges,
  cornerRadii,
  selectedIds,
  style,
  globalRadius,
  smoothing = 0.6,
  snapToGrid,
  showGrid,
  gridSize,
  presets = [],
  onAddShape,
  onDeleteShapes,
  onDuplicateShapes,
  onStyleChange,
  onGlobalRadiusChange,
  onSmoothingChange,
  onShapeUpdate,
  onAlignShapes,
  onDistributeShapes,
  onApplyPreset,
  onToggleSnap,
  onToggleGrid,
  onGridSizeChange,
  toolSelector,
  disabled = false
})

Source from the content-addressed store, hash-verified

262);
263
264export default function Controls({
265 shapes,
266 bridges,
267 cornerRadii,
268 selectedIds,
269 style,
270 globalRadius,
271 smoothing = 0.6,
272 snapToGrid,
273 showGrid,
274 gridSize,
275 presets = [],
276 onAddShape,
277 onDeleteShapes,
278 onDuplicateShapes,
279 onStyleChange,
280 onGlobalRadiusChange,
281 onSmoothingChange,
282 onShapeUpdate,
283 onAlignShapes,
284 onDistributeShapes,
285 onApplyPreset,
286 onToggleSnap,
287 onToggleGrid,
288 onGridSizeChange,
289 toolSelector,
290 disabled = false
291}) {
292 const [copyStatus, setCopyStatus] = useState(null);
293 const [shortcutsHovered, setShortcutsHovered] = useState(false);
294 const [pngScale, setPngScale] = useState('2');
295 const [exportPad, setExportPad] = useState(16);
296 const [includeBg, setIncludeBg] = useState(false);
297
298 const selectedShape = shapes.find(s => s.id === selectedIds[0]);
299 const hasMultiSelection = selectedIds.length > 1;
300 const hasThreeOrMoreSelected = selectedIds.length >= 3;
301
302 const setStyle = useCallback(patch => onStyleChange({ ...style, ...patch }), [onStyleChange, style]);
303
304 const exportOpts = { padding: exportPad, forceBackground: includeBg };
305
306 const flash = key => {
307 setCopyStatus(key);
308 setTimeout(() => setCopyStatus(null), 2000);
309 };
310
311 const handleCopySVG = useCallback(() => {
312 navigator.clipboard.writeText(
313 generateMergedSVG(shapes, bridges, cornerRadii || {}, style, globalRadius, smoothing, exportOpts)
314 );
315 flash('svg');
316 // eslint-disable-next-line react-hooks/exhaustive-deps
317 }, [shapes, bridges, cornerRadii, globalRadius, style, smoothing, exportPad, includeBg]);
318
319 const handleCopyReact = useCallback(() => {
320 navigator.clipboard.writeText(
321 generateReactComponent(shapes, bridges, cornerRadii || {}, style, globalRadius, smoothing)

Callers

nothing calls this directly

Calls 5

generateMergedSVGFunction · 0.90
generateReactComponentFunction · 0.90
generateCSSClipPathFunction · 0.90
flashFunction · 0.85

Tested by

no test coverage detected