From eee2b342df9c1dd0a1688dc4cf3838206495a69f Mon Sep 17 00:00:00 2001 From: Konstantinos Kaloutas Date: Wed, 26 Oct 2022 20:15:16 +0300 Subject: [PATCH] chore: color system enhancements --- .../ContextBar/contextBarActionFactory.tsx | 18 +++++------ .../src/components/inputs/ColorInput.tsx | 30 +++++++++---------- .../tldraw-logseq/src/lib/shapes/BoxShape.tsx | 2 +- .../src/lib/shapes/LogseqPortalShape.tsx | 11 ++++--- tldraw/apps/tldraw-logseq/src/styles.css | 14 ++++++--- 5 files changed, 37 insertions(+), 38 deletions(-) diff --git a/tldraw/apps/tldraw-logseq/src/components/ContextBar/contextBarActionFactory.tsx b/tldraw/apps/tldraw-logseq/src/components/ContextBar/contextBarActionFactory.tsx index 18bc059b4f..69c4e6ebdd 100644 --- a/tldraw/apps/tldraw-logseq/src/components/ContextBar/contextBarActionFactory.tsx +++ b/tldraw/apps/tldraw-logseq/src/components/ContextBar/contextBarActionFactory.tsx @@ -330,21 +330,17 @@ const SwatchAction = observer(() => { const shapes = filterShapeByAction< BoxShape | PolygonShape | EllipseShape | LineShape | PencilShape | TextShape >(app.selectedShapesArray, 'Swatch') - const handleChange = React.useMemo(() => { - let latestValue = '' - const handler: React.ChangeEventHandler = e => { - shapes.forEach(s => { - s.update({ fill: latestValue, stroke: latestValue }) - }) - app.persist() - } - return debounce(handler, 100, e => { - latestValue = e.target.value + + const handleClick = React.useCallback((e: React.MouseEvent) => { + const color = e.target.getAttribute("data-color") + shapes.forEach(s => { + s.update({ fill: color, stroke: color }) }) + app.persist() }, []) const value = shapes[0].props.noFill ? shapes[0].props.stroke : shapes[0].props.fill - return + return }) const StrokeTypeAction = observer(() => { diff --git a/tldraw/apps/tldraw-logseq/src/components/inputs/ColorInput.tsx b/tldraw/apps/tldraw-logseq/src/components/inputs/ColorInput.tsx index fd6f09dc9f..2d1173aae1 100644 --- a/tldraw/apps/tldraw-logseq/src/components/inputs/ColorInput.tsx +++ b/tldraw/apps/tldraw-logseq/src/components/inputs/ColorInput.tsx @@ -2,7 +2,7 @@ import * as React from 'react' import * as Popover from '@radix-ui/react-popover'; import { TablerIcon } from '../icons' -interface ColorInputProps extends React.InputHTMLAttributes {} +interface ColorInputProps extends React.InputHTMLAttributes {} enum HighlightColor { Gray = 'gray', @@ -12,9 +12,10 @@ enum HighlightColor { Blue = 'blue', Purple = 'purple', Pink = 'pink', + None = 'transparent', } -export function ColorInput({ value, onChange, ...rest }: ColorInputProps) { +export function ColorInput({ value, onClick, ...rest }: ColorInputProps) { const ref = React.useRef(null) const [computedValue, setComputedValue] = React.useState(value) @@ -31,12 +32,10 @@ export function ColorInput({ value, onChange, ...rest }: ColorInputProps) { return ( - +
-
@@ -48,19 +47,18 @@ export function ColorInput({ value, onChange, ...rest }: ColorInputProps) { arrowPadding={10} >
- {Object.values(HighlightColor).map(value => + {Object.values(HighlightColor).map(color => )} -
diff --git a/tldraw/apps/tldraw-logseq/src/lib/shapes/BoxShape.tsx b/tldraw/apps/tldraw-logseq/src/lib/shapes/BoxShape.tsx index 65ebe30ce0..bbfcf69d98 100644 --- a/tldraw/apps/tldraw-logseq/src/lib/shapes/BoxShape.tsx +++ b/tldraw/apps/tldraw-logseq/src/lib/shapes/BoxShape.tsx @@ -65,7 +65,7 @@ export class BoxShape extends TLBoxShape { strokeWidth={strokeWidth} stroke={noFill ? fill : stroke} strokeDasharray={strokeType === 'dashed' ? '8 2' : undefined} - fill={noFill ? 'none' : fill} + fill={noFill ? 'none' : `var(--color-${fill}-500)`} /> ) diff --git a/tldraw/apps/tldraw-logseq/src/lib/shapes/LogseqPortalShape.tsx b/tldraw/apps/tldraw-logseq/src/lib/shapes/LogseqPortalShape.tsx index 8e8c21f7e0..ae937ab1ce 100644 --- a/tldraw/apps/tldraw-logseq/src/lib/shapes/LogseqPortalShape.tsx +++ b/tldraw/apps/tldraw-logseq/src/lib/shapes/LogseqPortalShape.tsx @@ -152,7 +152,7 @@ const CircleButton = ({ }, [active]) return ( -
}
- + ) } @@ -181,7 +181,7 @@ export class LogseqPortalShape extends TLBoxShape { // collapsedHeight is the height before collapsing collapsedHeight: 0, stroke: 'var(--ls-primary-text-color)', - fill: 'var(--ls-secondary-background-color)', + fill: 'transparent', noFill: false, borderRadius: 8, strokeWidth: 2, @@ -661,7 +661,7 @@ export class LogseqPortalShape extends TLBoxShape { PortalComponent = observer(({}: TLComponentProps) => { const { - props: { pageId }, + props: { pageId, fill }, } = this const { renderers } = React.useContext(LogseqContext) const app = useApp() @@ -707,6 +707,7 @@ export class LogseqPortalShape extends TLBoxShape { ref={cpRefContainer} className="tl-logseq-cp-container" style={{ + background: `var(--ls-highlight-color-${fill})`, overflow: this.props.isAutoResizing ? 'visible' : 'auto', }} > @@ -838,8 +839,6 @@ export class LogseqPortalShape extends TLBoxShape { data-portal-selected={portalSelected} data-editing={isEditing} style={{ - background: this.props.compact ? 'transparent' : fill, - color: stroke, width: `calc(100% / ${scaleRatio})`, height: `calc(100% / ${scaleRatio})`, transform: `scale(${scaleRatio})`, diff --git a/tldraw/apps/tldraw-logseq/src/styles.css b/tldraw/apps/tldraw-logseq/src/styles.css index be8bce903b..c60f8d8b3e 100644 --- a/tldraw/apps/tldraw-logseq/src/styles.css +++ b/tldraw/apps/tldraw-logseq/src/styles.css @@ -647,6 +647,7 @@ button.tl-select-input-trigger { opacity: 1; user-select: text; transform-origin: top left; + background: var(--ls-secondary-background-color); &[data-collapsed='true'][data-editing='false'] { @apply overflow-hidden; @@ -850,8 +851,10 @@ html[data-theme='dark'] { } .tl-popover-content { - border-radius: 4px; - padding: 20px; + @apply rounded-sm; + + padding: 4px; + width: 160px; background-color: var(--ls-secondary-background-color); z-index: 100000; } @@ -861,12 +864,15 @@ html[data-theme='dark'] { } .tl-color-palette { - @apply flex; + @apply flex flex-wrap; } .tl-color-drip { + @apply rounded-sm; + width: 30px; height: 30px; - margin: 2px; + margin: 4px; border: 1px solid var(--ls-secondary-border-color); + color: var(--ls-secondary-text-color); }