Procházet zdrojové kódy

Improve style menu (#361)

* Change undo / redo icons, add undo/redo buttons, add Styles label

* Update TopPanel.tsx

* Fix breakpoints
main
Steve Ruiz před 3 roky
rodič
revize
d0206f485e
Žádný účet není propojen s e-mailovou adresou tvůrce revize

+ 1
- 0
packages/tldraw/src/components/Primitives/ToolButton/ToolButton.tsx Zobrazit soubor

@@ -141,6 +141,7 @@ export const StyledToolButton = styled('button', {
141 141
         [`& ${StyledToolButtonInner}`]: {
142 142
           fontSize: '$1',
143 143
           padding: '0 $3',
144
+          gap: '$3',
144 145
         },
145 146
       },
146 147
       circle: {

+ 2
- 11
packages/tldraw/src/components/Primitives/icons/RedoIcon.tsx Zobrazit soubor

@@ -2,17 +2,8 @@ import * as React from 'react'
2 2
 
3 3
 export function RedoIcon(props: React.SVGProps<SVGSVGElement>): JSX.Element {
4 4
   return (
5
-    <svg viewBox="0 -1 15 15" fill="currentColor" xmlns="http://www.w3.org/2000/svg" {...props}>
6
-      <path
7
-        fillRule="evenodd"
8
-        clipRule="evenodd"
9
-        d="M12.5 2.495a.5.5 0 00-.5.5v2.5H9.5a.5.5 0 100 1h3a.5.5 0 00.5-.5v-3a.5.5 0 00-.5-.5z"
10
-      />
11
-      <path
12
-        fillRule="evenodd"
13
-        clipRule="evenodd"
14
-        d="M7.697 2.049a5 5 0 104.02 6.613.5.5 0 10-.944-.332 4 4 0 11-.946-4.16l.01.01 2.32 2.18a.5.5 0 00.685-.729l-2.314-2.175A5 5 0 007.697 2.05z"
15
-      />
5
+    <svg viewBox="0 0 15 15" fill="currentColor" xmlns="http://www.w3.org/2000/svg" {...props}>
6
+      <path d="M4.32978 8.5081C4.32978 10.1923 5.70009 11.5625 7.38418 11.5625H8.46539C8.64456 11.5625 8.78975 11.4173 8.78975 11.2382V11.13C8.78975 10.9508 8.64457 10.8057 8.46539 10.8057H7.38418C6.11736 10.8057 5.08662 9.77492 5.08662 8.5081C5.08662 7.24128 6.11736 6.21054 7.38418 6.21054H9.37894L8.00515 7.58433C7.8576 7.73183 7.8576 7.97195 8.00515 8.11944C8.14833 8.26251 8.39751 8.2623 8.54036 8.11944L10.56 6.09971C10.6315 6.02824 10.6709 5.93321 10.6709 5.8321C10.6709 5.73106 10.6315 5.63598 10.56 5.56454L8.54025 3.54472C8.3974 3.40176 8.14801 3.40176 8.00513 3.54472C7.85758 3.69218 7.85758 3.93234 8.00513 4.07979L9.37892 5.45368H7.38418C5.70009 5.45368 4.32978 6.82393 4.32978 8.5081Z" />
16 7
     </svg>
17 8
   )
18 9
 }

+ 2
- 11
packages/tldraw/src/components/Primitives/icons/UndoIcon.tsx Zobrazit soubor

@@ -2,17 +2,8 @@ import * as React from 'react'
2 2
 
3 3
 export function UndoIcon(props: React.SVGProps<SVGSVGElement>): JSX.Element {
4 4
   return (
5
-    <svg viewBox="0 -1 15 15" fill="currentColor" xmlns="http://www.w3.org/2000/svg" {...props}>
6
-      <path
7
-        fillRule="evenodd"
8
-        clipRule="evenodd"
9
-        d="M2.5 2.495a.5.5 0 01.5.5v2.5h2.5a.5.5 0 110 1h-3a.5.5 0 01-.5-.5v-3a.5.5 0 01.5-.5z"
10
-      />
11
-      <path
12
-        fillRule="evenodd"
13
-        clipRule="evenodd"
14
-        d="M7.303 2.049a5 5 0 11-4.02 6.613.5.5 0 01.944-.332 4 4 0 10.946-4.16l-.01.01-2.32 2.18a.5.5 0 01-.685-.729l2.314-2.175A5 5 0 017.303 2.05z"
15
-      />
5
+    <svg viewBox="0 0 15 15" fill="currentColor" xmlns="http://www.w3.org/2000/svg" {...props}>
6
+      <path d="M10.6707 8.5081C10.6707 10.1923 9.3004 11.5625 7.61631 11.5625H6.5351C6.35593 11.5625 6.21074 11.4173 6.21074 11.2382V11.13C6.21074 10.9508 6.35591 10.8057 6.5351 10.8057H7.61631C8.88313 10.8057 9.91387 9.77492 9.91387 8.5081C9.91387 7.24128 8.88313 6.21054 7.61631 6.21054H5.62155L6.99534 7.58433C7.14289 7.73183 7.14289 7.97195 6.99534 8.11944C6.85216 8.26251 6.60298 8.2623 6.46013 8.11944L4.44045 6.09971C4.36898 6.02824 4.32959 5.93321 4.32959 5.8321C4.32959 5.73106 4.36898 5.63598 4.44045 5.56454L6.46024 3.54472C6.60309 3.40176 6.85248 3.40176 6.99535 3.54472C7.14291 3.69218 7.14291 3.93234 6.99535 4.07979L5.62156 5.45368H7.61631C9.3004 5.45368 10.6707 6.82393 10.6707 8.5081Z" />
16 7
     </svg>
17 8
   )
18 9
 }

+ 20
- 16
packages/tldraw/src/components/TopPanel/StyleMenu/StyleMenu.tsx Zobrazit soubor

@@ -38,6 +38,7 @@ import {
38 38
   TextAlignLeftIcon,
39 39
   TextAlignRightIcon,
40 40
 } from '@radix-ui/react-icons'
41
+import { RowButton } from '~components/Primitives/RowButton'
41 42
 
42 43
 const currentStyleSelector = (s: TDSnapshot) => s.appState.currentStyle
43 44
 const selectedIdsSelector = (s: TDSnapshot) =>
@@ -149,22 +150,25 @@ export const StyleMenu = React.memo(function ColorMenu(): JSX.Element {
149 150
 
150 151
   return (
151 152
     <DropdownMenu.Root dir="ltr">
152
-      <DMTriggerIcon>
153
-        <OverlapIcons
154
-          style={{
155
-            color: strokes[theme][displayedStyle.color as ColorStyle],
156
-          }}
157
-        >
158
-          {displayedStyle.isFilled && (
159
-            <CircleIcon
160
-              size={16}
161
-              stroke="none"
162
-              fill={fills[theme][displayedStyle.color as ColorStyle]}
163
-            />
164
-          )}
165
-          {DASH_ICONS[displayedStyle.dash]}
166
-        </OverlapIcons>
167
-      </DMTriggerIcon>
153
+      <DropdownMenu.Trigger asChild>
154
+        <ToolButton variant="text">
155
+          Styles
156
+          <OverlapIcons
157
+            style={{
158
+              color: strokes[theme][displayedStyle.color as ColorStyle],
159
+            }}
160
+          >
161
+            {displayedStyle.isFilled && (
162
+              <CircleIcon
163
+                size={16}
164
+                stroke="none"
165
+                fill={fills[theme][displayedStyle.color as ColorStyle]}
166
+              />
167
+            )}
168
+            {DASH_ICONS[displayedStyle.dash]}
169
+          </OverlapIcons>
170
+        </ToolButton>
171
+      </DropdownMenu.Trigger>
168 172
       <DMContent>
169 173
         <StyledRow variant="tall">
170 174
           <span>Color</span>

+ 29
- 0
packages/tldraw/src/components/TopPanel/TopPanel.tsx Zobrazit soubor

@@ -5,6 +5,10 @@ import { PageMenu } from './PageMenu'
5 5
 import { ZoomMenu } from './ZoomMenu'
6 6
 import { StyleMenu } from './StyleMenu'
7 7
 import { Panel } from '~components/Primitives/Panel'
8
+import { ToolButton } from '~components/Primitives/ToolButton'
9
+import { RedoIcon, UndoIcon } from '~components/Primitives/icons'
10
+import { breakpoints } from '~components/breakpoints'
11
+import { useTldrawApp } from '~hooks'
8 12
 
9 13
 interface TopPanelProps {
10 14
   readOnly: boolean
@@ -23,6 +27,8 @@ export function TopPanel({
23 27
   showZoom,
24 28
   showSponsorLink,
25 29
 }: TopPanelProps) {
30
+  const app = useTldrawApp()
31
+
26 32
   return (
27 33
     <StyledTopPanel>
28 34
       {(showMenu || showPages) && (
@@ -35,6 +41,14 @@ export function TopPanel({
35 41
       {(showStyles || showZoom) && (
36 42
         <Panel side="right">
37 43
           {showStyles && !readOnly && <StyleMenu />}
44
+          <MobileOnly bp={breakpoints}>
45
+            <ToolButton>
46
+              <UndoIcon onClick={app.undo} />
47
+            </ToolButton>
48
+            <ToolButton>
49
+              <RedoIcon onClick={app.redo} />
50
+            </ToolButton>
51
+          </MobileOnly>
38 52
           {showZoom && <ZoomMenu />}
39 53
         </Panel>
40 54
       )}
@@ -60,3 +74,18 @@ const StyledSpacer = styled('div', {
60 74
   flexGrow: 2,
61 75
   pointerEvents: 'none',
62 76
 })
77
+
78
+const MobileOnly = styled('div', {
79
+  display: 'flex',
80
+  flexDirection: 'row',
81
+  variants: {
82
+    bp: {
83
+      small: {
84
+        display: 'inherit',
85
+      },
86
+      medium: {
87
+        display: 'none',
88
+      },
89
+    },
90
+  },
91
+})

+ 6
- 1
packages/tldraw/src/components/breakpoints.tsx Zobrazit soubor

@@ -3,4 +3,9 @@
3 3
 /* -------------------------------------------------- */
4 4
 
5 5
 // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
-export const breakpoints: any = { '@initial': 'mobile', '@sm': 'small' }
6
+export const breakpoints: any = {
7
+  '@initial': 'mobile',
8
+  '@micro': 'micro',
9
+  '@sm': 'small',
10
+  '@md': 'medium',
11
+}

+ 2
- 1
packages/tldraw/src/styles/stitches.config.ts Zobrazit soubor

@@ -32,7 +32,8 @@ const { styled, createTheme } = createStitches({
32 32
       key: '1px 1px rgba(0,0,0,1)',
33 33
       panel: `0px 0px 16px -1px rgba(0, 0, 0, 0.05), 
34 34
         0px 0px 16px -8px rgba(0, 0, 0, 0.05), 
35
-        0px 0px 16px -12px rgba(0, 0, 0, 0.12)`,
35
+        0px 0px 16px -12px rgba(0, 0, 0, 0.12),
36
+        0px 0px 2px 0px rgba(0, 0, 0, 0.08)`,
36 37
     },
37 38
     space: {
38 39
       0: '2px',

Načítá se…
Zrušit
Uložit