Skip to content

Commit 80c5731

Browse files
✨ Add collapsed state
1 parent 7f0f746 commit 80c5731

1 file changed

Lines changed: 57 additions & 24 deletions

File tree

code.tsx

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function getKeyDecorator(column: Column): KeyDecorator {
5959

6060
function DatabaseTableWidget() {
6161
const [theme, setTheme] = useSyncedState("theme", "#000c86")
62+
const [collapsed, setCollapsed] = useSyncedState("collapsed", false)
6263
const [tableName, setTableName] = useSyncedState("tableName", null)
6364
const [columns, setColumns] = useSyncedState("columns", (): Column[] => [])
6465

@@ -92,6 +93,11 @@ function DatabaseTableWidget() {
9293
tooltip: "Edit table",
9394
propertyName: "edit",
9495
},
96+
{
97+
itemType: "action",
98+
tooltip: collapsed ? "Expand" : "Collapse",
99+
propertyName: "collapse",
100+
},
95101
],
96102
({ propertyName, propertyValue }) => {
97103
switch (propertyName) {
@@ -107,6 +113,8 @@ function DatabaseTableWidget() {
107113
})
108114
figma.ui.postMessage(columns)
109115
})
116+
case "collapse":
117+
return setCollapsed((state) => !state)
110118
}
111119
}
112120
)
@@ -143,50 +151,75 @@ function DatabaseTableWidget() {
143151
/>
144152
</AutoLayout>
145153

146-
{columns.map((column) => {
147-
let { icon, color } = getKeyDecorator(column)
148-
149-
return (
154+
{
155+
collapsed ? (
150156
<AutoLayout
151157
width={400}
152158
height={48}
153159
padding={{
154160
right: 16,
155161
}}
156-
key={column.name}
157162
stroke="#e6e6e6"
158163
fill="#ffffff"
159164
verticalAlignItems="center"
160165
horizontalAlignItems="center"
161166
>
162167
<Text
163-
width={32}
164-
height={32}
165168
fontSize={18}
166169
fontFamily="Font Awesome 5 Free"
167170
fontWeight={900}
168-
fill={color}
169171
verticalAlignText="center"
170172
horizontalAlignText="center"
173+
onClick={() => setCollapsed(false)}
171174
>
172-
{icon}
173-
</Text>
174-
<Text
175-
width="fill-parent"
176-
fontFamily="Fira Code"
177-
fontSize={18}
178-
>
179-
{column.name}
180-
</Text>
181-
<Text
182-
fontFamily="Fira Code"
183-
fontSize={18}
184-
>
185-
{column.type}{column.nullable ? "?" : ""}
175+
{columns.length} collapsed fields. Click to reveal
186176
</Text>
187177
</AutoLayout>
188-
)
189-
})}
178+
) : columns.map((column) => {
179+
let { icon, color } = getKeyDecorator(column)
180+
181+
return (
182+
<AutoLayout
183+
width={400}
184+
height={48}
185+
padding={{
186+
right: 16,
187+
}}
188+
key={column.name}
189+
stroke="#e6e6e6"
190+
fill="#ffffff"
191+
verticalAlignItems="center"
192+
horizontalAlignItems="center"
193+
>
194+
<Text
195+
width={32}
196+
height={32}
197+
fontSize={18}
198+
fontFamily="Font Awesome 5 Free"
199+
fontWeight={900}
200+
fill={color}
201+
verticalAlignText="center"
202+
horizontalAlignText="center"
203+
>
204+
{icon}
205+
</Text>
206+
<Text
207+
width="fill-parent"
208+
fontFamily="Fira Code"
209+
fontSize={18}
210+
>
211+
{column.name}
212+
</Text>
213+
<Text
214+
fontFamily="Fira Code"
215+
fontSize={18}
216+
>
217+
{column.type}{column.nullable ? "?" : ""}
218+
</Text>
219+
</AutoLayout>
220+
)
221+
})
222+
}
190223
</AutoLayout>
191224
)
192225
}

0 commit comments

Comments
 (0)