开源白板工具(SaaS),一体化白板,包含思维导图、流程图、自由画等。All in one open-source whiteboard tool with mind, flowchart, freehand and etc.
feat: rename active-toolbar to popup-toolbar and modify tool-button
pubuzhixing8aa06c7e05842
diff --git a/packages/drawnix/src/components/color-picker.tsx b/packages/drawnix/src/components/color-picker.tsxindex 1e1eb90..e6791c3 100644--- a/packages/drawnix/src/components/color-picker.tsx+++ b/packages/drawnix/src/components/color-picker.tsx@@ -1,12 +1,10 @@-import { CSSProperties, useState } from 'react';+import { useState } from 'react';import { Check, TransparentIcon } from './icons';-import { Island } from './island';import Stack from '../components/stack';import './color-picker.scss';import { splitRows } from '../utils';-import classNames from 'classnames';-import { ATTACHED_ELEMENT_CLASS_NAME } from '@plait/core';import React from 'react';+import { SizeSlider } from './size-slider';const CLASSIC_COLORS = [{ name: 'Transparent', value: 'transparent' },@@ -31,24 +29,20 @@ const ROWS_CLASSIC_COLORS = splitRows(CLASSIC_COLORS, 4);export type ColorPickerProps = {onSelect: (color: string) => void;currentColor?: string;- style?: CSSProperties;- className?: string;};export const ColorPicker = React.forwardRef((props: ColorPickerProps, ref) => {const { onSelect, currentColor } = props;- const innerRef = React.useRef(null);- React.useImperativeHandle(ref, () => innerRef.current);const [selectedColor, setSelectedColor] = useState(currentColor || ROWS_CLASSIC_COLORS[0][0].value);return (- <Island- ref={innerRef}- padding={4}- className={classNames(`${ATTACHED_ELEMENT_CLASS_NAME}`, props.className)}- style={props.style}- >+ <>+ {/* <SizeSlider+ step={4}+ defaultValue={100}+ onChange={(value) => {}}+ ></SizeSlider> */}<Stack.Col gap={2}>{ROWS_CLASSIC_COLORS.map((colors, index) => (<Stack.Row key={index} gap={2}>@@ -77,6 +71,6 @@ export const ColorPicker = React.forwardRef((props: ColorPickerProps, ref) => {</Stack.Row>))}</Stack.Col>- </Island>+ </>);});diff --git a/packages/drawnix/src/components/icons.tsx b/packages/drawnix/src/components/icons.tsxindex 7f87ebe..b019012 100644--- a/packages/drawnix/src/components/icons.tsx+++ b/packages/drawnix/src/components/icons.tsx@@ -301,6 +301,40 @@ export const StrokeIcon = createIcon(</svg>);+export const StrokeStyleNormalIcon = createIcon(+ <svg viewBox="0 0 24 32" xmlns="http://www.w3.org/2000/svg">+ <g transform="translate(0 14)" fillRule="evenodd" fill="none">+ <path d="M-18-19h60v40h-60z"></path>+ <path d="M0 0h24v2H0z" fill="currentColor"></path>+ </g>+ </svg>+);++export const StrokeStyleDashedIcon = createIcon(+ <svg viewBox="0 0 24 32" xmlns="http://www.w3.org/2000/svg">+ <g transform="translate(0 14)" fillRule="evenodd" fill="none">+ <g fill="currentColor">+ <path d="M0 0h6v2H0zM9 0h6v2H9zM18 0h6v2h-6z"></path>+ </g>+ </g>+ </svg>+);++export const StrokeStyleDotedIcon = createIcon(+ <svg viewBox="0 0 24 32" xmlns="http://www.w3.org/2000/svg">+ <g transform="translate(0 14)" fillRule="evenodd" fill="none">+ <g fill="currentColor">+ <rect rx="1" height="2" width="2"></rect>+ <rect rx="1" x="4" height="2" width="2"></rect>+ <rect rx="1" x="8" height="2" width="2"></rect>+ <rect rx="1" x="12" height="2" width="2"></rect>+ <rect rx="1" x="16" height="2" width="2"></rect>+ <rect rx="1" x="20" height="2" width="2"></rect>+ </g>+ </g>+ </svg>+);+export const FontColorIcon: React.FC<{ currentColor?: string }> = ({currentColor,}) => {diff --git a/packages/drawnix/src/components/popup-toolbar/fill-button.tsx b/packages/drawnix/src/components/popup-toolbar/fill-button.tsxnew file mode 100644index 0000000..190d09f--- /dev/null+++ b/packages/drawnix/src/components/popup-toolbar/fill-button.tsx@@ -0,0 +1,83 @@+import React, { ReactNode, useState } from 'react';+import { ToolButton } from '../tool-button';+import classNames from 'classnames';+import {+ autoUpdate,+ flip,+ offset,+ useClick,+ useDismiss,+ useFloating,+ useInteractions,+ useRole,+} from '@floating-ui/react';+import { ATTACHED_ELEMENT_CLASS_NAME } from '@plait/core';+import { Island } from '../island';+import { ColorPicker } from '../color-picker';++export type PopupFillButtonProps = {+ currentColor: string | undefined;+ transparentIcon: ReactNode;+ title: string;+ children?: React.ReactNode;+ onColorSelect: (selectedColor: string) => void;+};++export const PopupFillButton: React.FC<PopupFillButtonProps> = ({+ currentColor,+ transparentIcon,+ title,+ children,+ onColorSelect,+}) => {+ const [isOpen, setIsOpen] = useState(false);+ const { refs, floatingStyles, context } = useFloating({+ placement: 'left',+ open: isOpen,+ onOpenChange: setIsOpen,+ whileElementsMounted: autoUpdate,+ middleware: [offset(8), flip()],+ });++ const click = useClick(context);+ const dismiss = useDismiss(context);+ const role = useRole(context);++ const { getReferenceProps } = useInteractions([click, dismiss, role]);++ return (+ <>+ <ToolButton+ className={classNames(`property-button`)}+ visible={true}+ icon={+ currentColor && currentColor !== 'transparent'+ ? undefined+ : transparentIcon+ }+ type="button"+ title={title}+ aria-label={title}+ ref={refs.setReference}+ {...getReferenceProps()}+ >+ {currentColor && currentColor !== 'transparent' && children}+ </ToolButton>+ {isOpen && (+ <Island+ ref={refs.setFloating}+ style={floatingStyles}+ padding={4}+ className={classNames(`${ATTACHED_ELEMENT_CLASS_NAME}`)}+ >+ <ColorPicker+ onSelect={(selectedColor) => {+ onColorSelect(selectedColor);+ }}+ currentColor={currentColor}+ ></ColorPicker>+ </Island>+ )}+ </>+ );+};diff --git a/packages/drawnix/src/components/popup-toolbar/font-color-button.tsx b/packages/drawnix/src/components/popup-toolbar/font-color-button.tsxnew file mode 100644index 0000000..3bee42a--- /dev/null+++ b/packages/drawnix/src/components/popup-toolbar/font-color-button.tsx@@ -0,0 +1,75 @@+import React, { ReactNode, useState } from 'react';+import { ColorPicker } from '../color-picker';+import { ToolButton } from '../tool-button';+import classNames from 'classnames';+import {+ autoUpdate,+ flip,+ offset,+ useClick,+ useDismiss,+ useFloating,+ useInteractions,+ useRole,+} from '@floating-ui/react';+import { Island } from '../island';+import { ATTACHED_ELEMENT_CLASS_NAME } from '@plait/core';++export type PopupFontColorButtonProps = {+ currentColor: string | undefined;+ fontColorIcon: ReactNode;+ title: string;+ onSelect: (selectedColor: string) => void;+};++export const PopupFontColorButton: React.FC<PopupFontColorButtonProps> = ({+ currentColor,+ fontColorIcon,+ title,+ onSelect,+}) => {+ const [isOpen, setIsOpen] = useState(false);+ const { refs, floatingStyles, context } = useFloating({+ placement: 'left',+ open: isOpen,+ onOpenChange: setIsOpen,+ whileElementsMounted: autoUpdate,+ middleware: [offset(8), flip()],+ });++ const click = useClick(context);+ const dismiss = useDismiss(context);+ const role = useRole(context);++ const { getReferenceProps } = useInteractions([click, dismiss, role]);++ return (+ <>+ <ToolButton+ className={classNames(`property-button`)}+ visible={true}+ icon={fontColorIcon}+ type="button"+ title={title}+ aria-label={title}+ ref={refs.setReference}+ {...getReferenceProps()}+ ></ToolButton>+ {isOpen && (+ <Island+ ref={refs.setFloating}+ style={floatingStyles}+ padding={4}+ className={classNames(`${ATTACHED_ELEMENT_CLASS_NAME}`)}+ >+ <ColorPicker+ onSelect={(selectedColor) => {+ onSelect(selectedColor);+ }}+ currentColor={currentColor}+ ></ColorPicker>+ </Island>+ )}+ </>+ );+};diff --git a/packages/drawnix/src/components/toolbar/active-toolbar.scss b/packages/drawnix/src/components/popup-toolbar/popup-toolbar.scsssimilarity index 98%rename from packages/drawnix/src/components/toolbar/active-toolbar.scssrename to packages/drawnix/src/components/popup-toolbar/popup-toolbar.scssindex 6492bee..80eb975 100644--- a/packages/drawnix/src/components/toolbar/active-toolbar.scss+++ b/packages/drawnix/src/components/popup-toolbar/popup-toolbar.scss@@ -1,4 +1,4 @@-.active-toolbar {+.popup-toolbar {.property-button {height: var(--lg-button-size);width: var(--lg-button-size);diff --git a/packages/drawnix/src/components/toolbar/active-toolbar.tsx b/packages/drawnix/src/components/popup-toolbar/popup-toolbar.tsxsimilarity index 91%rename from packages/drawnix/src/components/toolbar/active-toolbar.tsxrename to packages/drawnix/src/components/popup-toolbar/popup-toolbar.tsxindex f78309d..0ebedf0 100644--- a/packages/drawnix/src/components/toolbar/active-toolbar.tsx+++ b/packages/drawnix/src/components/popup-toolbar/popup-toolbar.tsx@@ -19,7 +19,7 @@ import { flip, offset, useFloating } from '@floating-ui/react';import { Island } from '../island';import classNames from 'classnames';import { getStrokeByMindElement, MindElement } from '@plait/mind';-import './active-toolbar.scss';+import './popup-toolbar.scss';import {DrawTransforms,getMemorizeKey,@@ -29,20 +29,19 @@ import {isDrawElementsIncludeText,PlaitDrawElement,} from '@plait/draw';-import {- ActiveColorToolButton,- ActiveFontColorToolButton,-} from './color-tool-button';import { CustomText, PropertyTransforms } from '@plait/common';import {getTextMarksByElement,PlaitMarkEditor,TextTransforms,} from '@plait/text-plugins';+import { PopupFontColorButton } from './font-color-button';+import { PopupStrokeButton } from './stroke-button';+import { PopupFillButton } from './fill-button';-export type DrawActiveProps = {};+export type PopupToolbarProps = {};-export const ActiveToolbar: React.FC<DrawActiveProps> = ({}) => {+export const PopupToolbar: React.FC<PopupToolbarProps> = ({}) => {const board = useBoard();const selectedElements = getSelectedElements(board);const [movingOrDragging, setMovingOrDragging] = useState(false);@@ -140,13 +139,13 @@ export const ActiveToolbar: React.FC<DrawActiveProps> = ({}) => {{open && !movingOrDragging && (<Islandpadding={1}- className={classNames('active-toolbar', ATTACHED_ELEMENT_CLASS_NAME)}+ className={classNames('popup-toolbar', ATTACHED_ELEMENT_CLASS_NAME)}ref={refs.setFloating}style={floatingStyles}><Stack.Row gap={1}>{state.hasFontColor && (- <ActiveFontColorToolButton+ <PopupFontColorButtonkey={0}currentColor={state.fontColor}title={`Font Color`}@@ -161,14 +160,15 @@ export const ActiveToolbar: React.FC<DrawActiveProps> = ({}) => {getSelectedTableCellsEditor(board));}}- ></ActiveFontColorToolButton>+ ></PopupFontColorButton>)}- <ActiveColorToolButton+ <PopupStrokeButtonkey={1}currentColor={state.strokeColor}+ // currentOpacity={state}title={`Stroke`}transparentIcon={StrokeIcon}- onSelect={(selectedColor: string) => {+ onColorSelect={(selectedColor: string) => {console.log(`selectedColor: ${selectedColor}`);PropertyTransforms.setStrokeColor(board, selectedColor, {getMemorizeKey,@@ -181,14 +181,14 @@ export const ActiveToolbar: React.FC<DrawActiveProps> = ({}) => {})}style={{ borderColor: state.strokeColor }}></label>- </ActiveColorToolButton>+ </PopupStrokeButton>{state.hasFill && (- <ActiveColorToolButton+ <PopupFillButtonkey={2}currentColor={state.fill}title={`Fill Color`}transparentIcon={BackgroundColorIcon}- onSelect={(selectedColor: string) => {+ onColorSelect={(selectedColor: string) => {PropertyTransforms.setFillColor(board, selectedColor, {getMemorizeKey,callback: (element: PlaitElement, path: Path) => {@@ -220,7 +220,7 @@ export const ActiveToolbar: React.FC<DrawActiveProps> = ({}) => {})}style={{ backgroundColor: state.fill }}></label>- </ActiveColorToolButton>+ </PopupFillButton>)}</Stack.Row></Island>diff --git a/packages/drawnix/src/components/popup-toolbar/stroke-button.tsx b/packages/drawnix/src/components/popup-toolbar/stroke-button.tsxnew file mode 100644index 0000000..10108d9--- /dev/null+++ b/packages/drawnix/src/components/popup-toolbar/stroke-button.tsx@@ -0,0 +1,83 @@+import React, { ReactNode, useState } from 'react';+import { ToolButton } from '../tool-button';+import classNames from 'classnames';+import {+ autoUpdate,+ flip,+ offset,+ useClick,+ useDismiss,+ useFloating,+ useInteractions,+ useRole,+} from '@floating-ui/react';+import { ATTACHED_ELEMENT_CLASS_NAME } from '@plait/core';+import { Island } from '../island';+import { ColorPicker } from '../color-picker';++export type PopupStrokeButtonProps = {+ currentColor: string | undefined;+ transparentIcon: ReactNode;+ title: string;+ children?: React.ReactNode;+ onColorSelect: (selectedColor: string) => void;+};++export const PopupStrokeButton: React.FC<PopupStrokeButtonProps> = ({+ currentColor,+ transparentIcon,+ title,+ children,+ onColorSelect,+}) => {+ const [isOpen, setIsOpen] = useState(false);+ const { refs, floatingStyles, context } = useFloating({+ placement: 'left',+ open: isOpen,+ onOpenChange: setIsOpen,+ whileElementsMounted: autoUpdate,+ middleware: [offset(8), flip()],+ });++ const click = useClick(context);+ const dismiss = useDismiss(context);+ const role = useRole(context);++ const { getReferenceProps } = useInteractions([click, dismiss, role]);++ return (+ <>+ <ToolButton+ className={classNames(`property-button`)}+ visible={true}+ icon={+ currentColor && currentColor !== 'transparent'+ ? undefined+ : transparentIcon+ }+ type="button"+ title={title}+ aria-label={title}+ ref={refs.setReference}+ {...getReferenceProps()}+ >+ {currentColor && currentColor !== 'transparent' && children}+ </ToolButton>+ {isOpen && (+ <Island+ ref={refs.setFloating}+ style={floatingStyles}+ padding={4}+ className={classNames(`${ATTACHED_ELEMENT_CLASS_NAME}`)}+ >+ <ColorPicker+ onSelect={(selectedColor) => {+ onColorSelect(selectedColor);+ }}+ currentColor={currentColor}+ ></ColorPicker>+ </Island>+ )}+ </>+ );+};diff --git a/packages/drawnix/src/components/size-slider.scss b/packages/drawnix/src/components/size-slider.scssnew file mode 100644index 0000000..e5180f6--- /dev/null+++ b/packages/drawnix/src/components/size-slider.scss@@ -0,0 +1,31 @@+@import "open-color/open-color.scss";++.slider-container {+ padding: 10px 0px;+ .slider-track {+ position: relative;+ height: 4px;+ background-color: var(--color-gray-20);+ border-radius: 2px;+ cursor: pointer;+ margin: 0 8px;+ }+ .slider-range {+ position: absolute;+ height: 100%;+ background-color: var(--color-primary);+ border-radius: 3px;+ }+ .slider-thumb {+ position: absolute;+ width: 12px;+ height: 12px;+ background-color: $oc-white;+ border: 2px solid var(--color-primary);+ border-radius: 50%;+ top: 50%;+ transform: translate(-50%, -50%);+ cursor: grab;+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1),+ }+}diff --git a/packages/drawnix/src/components/size-slider.tsx b/packages/drawnix/src/components/size-slider.tsxnew file mode 100644index 0000000..3e91483--- /dev/null+++ b/packages/drawnix/src/components/size-slider.tsx@@ -0,0 +1,74 @@+import React, { useState, useRef, useCallback } from 'react';++import './size-slider.scss';++interface SliderProps {+ min?: number;+ max?: number;+ step?: number;+ defaultValue?: number;+ onChange?: (value: number) => void;+}++export const SizeSlider: React.FC<SliderProps> = ({+ min = 0,+ max = 100,+ step = 2,+ defaultValue = 100,+ onChange,+}) => {+ const [value, setValue] = useState(defaultValue);+ const sliderRef = useRef<HTMLDivElement>(null);++ const handleSliderChange = useCallback(+ (event: React.MouseEvent<HTMLDivElement> | MouseEvent) => {+ if (sliderRef.current) {+ const rect = sliderRef.current.getBoundingClientRect();+ const x = event.clientX - rect.left;+ const percentage = Math.min(Math.max(x / rect.width, 0), 1);+ const newValue =+ Math.round((percentage * (max - min)) / step) * step + min;+ setValue(newValue);+ onChange && onChange(newValue);+ }+ },+ [min, max, step, onChange]+ );++ const handleMouseDown = useCallback(() => {+ const handleMouseMove = (e: MouseEvent) => handleSliderChange(e);+ const handleMouseUp = () => {+ document.removeEventListener('mousemove', handleMouseMove);+ document.removeEventListener('mouseup', handleMouseUp);+ };++ document.addEventListener('mousemove', handleMouseMove);+ document.addEventListener('mouseup', handleMouseUp);+ }, [handleSliderChange]);++ const percentage = ((value - min) / (max - min)) * 100;++ return (+ <div className="slider-container">+ <div+ ref={sliderRef}+ className="slider-track"+ onClick={handleSliderChange}+ onMouseDown={handleMouseDown}+ >+ <div+ className="slider-range"+ style={{+ width: `${percentage}%`,+ }}+ />+ <div+ className="slider-thumb"+ style={{+ left: `${percentage}%`,+ }}+ />+ </div>+ </div>+ );+};diff --git a/packages/drawnix/src/components/tool-button.tsx b/packages/drawnix/src/components/tool-button.tsxindex 862b72d..ba1aeab 100644--- a/packages/drawnix/src/components/tool-button.tsx+++ b/packages/drawnix/src/components/tool-button.tsx@@ -149,7 +149,9 @@ export const ToolButton = React.forwardRef((props: ToolButtonProps, ref) => {{props.showAriaLabel && (<div className="tool-icon__label">{props['aria-label']}</div>)}- {props.children}+ {props.children && (+ <div className="tool-icon__icon">{props.children}</div>+ )}</button>);}diff --git a/packages/drawnix/src/components/toolbar/color-tool-button.tsx b/packages/drawnix/src/components/toolbar/color-tool-button.tsxdeleted file mode 100644index 9f33a0a..0000000--- a/packages/drawnix/src/components/toolbar/color-tool-button.tsx+++ /dev/null@@ -1,127 +0,0 @@-import React, { ReactNode, useState } from 'react';-import { ColorPicker } from '../color-picker';-import { ToolButton } from '../tool-button';-import classNames from 'classnames';-import {- autoUpdate,- flip,- offset,- useClick,- useDismiss,- useFloating,- useInteractions,- useRole,-} from '@floating-ui/react';--export type ActiveColorToolButtonProps = {- currentColor: string | undefined;- transparentIcon: ReactNode;- title: string;- children?: React.ReactNode;- onSelect: (selectedColor: string) => void;-};--export type ActiveFontColorToolButtonProps = {- currentColor: string | undefined;- fontColorIcon: ReactNode;- title: string;- onSelect: (selectedColor: string) => void;-};--export const ActiveColorToolButton: React.FC<ActiveColorToolButtonProps> = ({- currentColor,- transparentIcon,- title,- children,- onSelect,-}) => {- const [isOpen, setIsOpen] = useState(false);- const { refs, floatingStyles, context } = useFloating({- placement: 'left',- open: isOpen,- onOpenChange: setIsOpen,- whileElementsMounted: autoUpdate,- middleware: [offset(8), flip()],- });-- const click = useClick(context);- const dismiss = useDismiss(context);- const role = useRole(context);-- const { getReferenceProps } = useInteractions([click, dismiss, role]);-- return (- <>- <ToolButton- className={classNames(`property-button`)}- visible={true}- icon={- currentColor && currentColor !== 'transparent'- ? undefined- : transparentIcon- }- type="button"- title={title}- aria-label={title}- ref={refs.setReference}- {...getReferenceProps()}- >- {currentColor && currentColor !== 'transparent' && children}- </ToolButton>- {isOpen && (- <ColorPicker- ref={refs.setFloating}- style={floatingStyles}- onSelect={(selectedColor) => {- onSelect(selectedColor);- }}- currentColor={currentColor}- ></ColorPicker>- )}- </>- );-};--export const ActiveFontColorToolButton: React.FC<- ActiveFontColorToolButtonProps-> = ({ currentColor, fontColorIcon, title, onSelect }) => {- const [isOpen, setIsOpen] = useState(false);- const { refs, floatingStyles, context } = useFloating({- placement: 'left',- open: isOpen,- onOpenChange: setIsOpen,- whileElementsMounted: autoUpdate,- middleware: [offset(8), flip()],- });-- const click = useClick(context);- const dismiss = useDismiss(context);- const role = useRole(context);-- const { getReferenceProps } = useInteractions([click, dismiss, role]);-- return (- <>- <ToolButton- className={classNames(`property-button`)}- visible={true}- icon={fontColorIcon}- type="button"- title={title}- aria-label={title}- ref={refs.setReference}- {...getReferenceProps()}- ></ToolButton>- {isOpen && (- <ColorPicker- ref={refs.setFloating}- style={floatingStyles}- onSelect={(selectedColor) => {- onSelect(selectedColor);- }}- currentColor={currentColor}- ></ColorPicker>- )}- </>- );-};diff --git a/packages/drawnix/src/drawnix.tsx b/packages/drawnix/src/drawnix.tsxindex 406141e..7309199 100644--- a/packages/drawnix/src/drawnix.tsx+++ b/packages/drawnix/src/drawnix.tsx@@ -19,7 +19,7 @@ import { DrawToolbar } from './components/toolbar/draw-toolbar';import './styles/index.scss';import { MainMenu } from './components/main-menu/main-menu';import { ZoomToolbar } from './components/toolbar/zoom-toolbar';-import { ActiveToolbar } from './components/toolbar/active-toolbar';+import { PopupToolbar } from './components/popup-toolbar/popup-toolbar';export type DrawnixProps = {value: PlaitElement[];@@ -72,7 +72,7 @@ export const Drawnix: React.FC<DrawnixProps> = ({ value, onChange }) => {}}></DrawToolbar><ZoomToolbar></ZoomToolbar>- <ActiveToolbar></ActiveToolbar>+ <PopupToolbar></PopupToolbar></Wrapper></div>);diff --git a/packages/drawnix/src/styles/index.scss b/packages/drawnix/src/styles/index.scssindex 977b457..4112e77 100644--- a/packages/drawnix/src/styles/index.scss+++ b/packages/drawnix/src/styles/index.scss@@ -4,6 +4,7 @@.drawnix {height: 100%;+ font-family: PingFangSC-Regular, "PingFang SC";.draw-toolbar {cursor: default;position: absolute;