Skip to content

Commit 0f94c86

Browse files
committed
feat: use ressetable blue label for properties
- properties now have blue labels when value is specified - clicking on label shows tooltip - alt+click does reset/delete
1 parent dd08852 commit 0f94c86

File tree

16 files changed

+280
-249
lines changed

16 files changed

+280
-249
lines changed

Diff for: apps/builder/app/builder/features/settings-panel/controls/boolean.tsx

+3-11
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,19 @@ import {
66
} from "~/builder/shared/binding-popover";
77
import {
88
type ControlProps,
9-
Label,
10-
RemovePropButton,
119
$selectedInstanceScope,
1210
updateExpressionValue,
1311
useBindingState,
1412
humanizeAttribute,
1513
} from "../shared";
14+
import { PropertyLabel } from "../property-label";
1615

1716
export const BooleanControl = ({
1817
meta,
1918
prop,
2019
propName,
2120
computedValue,
22-
deletable,
2321
onChange,
24-
onDelete,
2522
}: ControlProps<"boolean">) => {
2623
const label = humanizeAttribute(meta.label || propName);
2724
const { scope, aliases } = useStore($selectedInstanceScope);
@@ -34,18 +31,14 @@ export const BooleanControl = ({
3431
return (
3532
<Grid
3633
css={{
37-
gridTemplateColumns: deletable
38-
? `1fr max-content max-content`
39-
: `1fr max-content`,
34+
gridTemplateColumns: `1fr max-content`,
4035
minHeight: theme.spacing[13],
4136
justifyItems: "start",
4237
}}
4338
align="center"
4439
gap="2"
4540
>
46-
<Label description={meta.description} readOnly={overwritable === false}>
47-
{label}
48-
</Label>
41+
<PropertyLabel name={propName} readOnly={overwritable === false} />
4942
<BindingControl>
5043
<Switch
5144
disabled={overwritable === false}
@@ -76,7 +69,6 @@ export const BooleanControl = ({
7669
}
7770
/>
7871
</BindingControl>
79-
{deletable && <RemovePropButton onClick={onDelete} />}
8072
</Grid>
8173
);
8274
};

Diff for: apps/builder/app/builder/features/settings-panel/controls/check.tsx

+2-11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
useBindingState,
1515
humanizeAttribute,
1616
} from "../shared";
17+
import { PropertyLabel } from "../property-label";
1718

1819
const add = (array: string[], item: string) => {
1920
if (array.includes(item)) {
@@ -34,9 +35,7 @@ export const CheckControl = ({
3435
prop,
3536
propName,
3637
computedValue,
37-
deletable,
3838
onChange,
39-
onDelete,
4039
}: ControlProps<"check" | "inline-check" | "multi-select">) => {
4140
const value = Array.isArray(computedValue)
4241
? computedValue.map((item) => String(item))
@@ -57,16 +56,8 @@ export const CheckControl = ({
5756
return (
5857
<VerticalLayout
5958
label={
60-
<Label
61-
htmlFor={`${id}:${options[0]}`}
62-
description={meta.description}
63-
readOnly={overwritable === false}
64-
>
65-
{label}
66-
</Label>
59+
<PropertyLabel name={propName} readOnly={overwritable === false} />
6760
}
68-
deletable={deletable}
69-
onDelete={onDelete}
7061
>
7162
<BindingControl>
7263
{options.map((option) => (

Diff for: apps/builder/app/builder/features/settings-panel/controls/code.tsx

+16-25
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
11
import { useStore } from "@nanostores/react";
2-
import { CodeEditor } from "~/builder/shared/code-editor";
3-
import {
4-
BindingControl,
5-
BindingPopover,
6-
} from "~/builder/shared/binding-popover";
7-
import {
8-
useLocalValue,
9-
type ControlProps,
10-
VerticalLayout,
11-
Label,
12-
updateExpressionValue,
13-
$selectedInstanceScope,
14-
useBindingState,
15-
humanizeAttribute,
16-
} from "../shared";
172
import { useState } from "react";
183
import {
194
Button,
@@ -29,6 +14,21 @@ import {
2914
theme,
3015
} from "@webstudio-is/design-system";
3116
import { InfoCircleIcon } from "@webstudio-is/icons";
17+
import { CodeEditor } from "~/builder/shared/code-editor";
18+
import {
19+
BindingControl,
20+
BindingPopover,
21+
} from "~/builder/shared/binding-popover";
22+
import {
23+
useLocalValue,
24+
type ControlProps,
25+
VerticalLayout,
26+
updateExpressionValue,
27+
$selectedInstanceScope,
28+
useBindingState,
29+
humanizeAttribute,
30+
} from "../shared";
31+
import { PropertyLabel } from "../property-label";
3232

3333
const ErrorInfo = ({
3434
error,
@@ -126,9 +126,7 @@ export const CodeControl = ({
126126
prop,
127127
propName,
128128
computedValue,
129-
deletable,
130129
onChange,
131-
onDelete,
132130
}: ControlProps<"code"> | ControlProps<"codetext">) => {
133131
const [error, setError] = useState<Error>();
134132
const metaOverride = {
@@ -177,17 +175,10 @@ export const CodeControl = ({
177175
<VerticalLayout
178176
label={
179177
<Flex gap="1" align="center">
180-
<Label
181-
description={metaOverride.description}
182-
readOnly={overwritable === false}
183-
>
184-
{label}
185-
</Label>
178+
<PropertyLabel name={propName} readOnly={overwritable === false} />
186179
{errorInfo}
187180
</Flex>
188181
}
189-
deletable={deletable}
190-
onDelete={onDelete}
191182
>
192183
<BindingControl>
193184
<CodeEditor

Diff for: apps/builder/app/builder/features/settings-panel/controls/file.tsx

+2-11
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import {
99
type ControlProps,
1010
VerticalLayout,
1111
useLocalValue,
12-
Label,
1312
updateExpressionValue,
1413
$selectedInstanceScope,
1514
useBindingState,
1615
humanizeAttribute,
1716
} from "../shared";
1817
import { SelectAsset } from "./select-asset";
18+
import { PropertyLabel } from "../property-label";
1919

2020
const UrlInput = ({
2121
id,
@@ -47,7 +47,6 @@ export const FileControl = ({
4747
prop,
4848
propName,
4949
computedValue,
50-
deletable,
5150
onChange,
5251
onDelete,
5352
}: ControlProps<"file">) => {
@@ -81,15 +80,7 @@ export const FileControl = ({
8180
);
8281

8382
return (
84-
<VerticalLayout
85-
label={
86-
<Label htmlFor={id} description={meta.description}>
87-
{label}
88-
</Label>
89-
}
90-
deletable={deletable}
91-
onDelete={onDelete}
92-
>
83+
<VerticalLayout label={<PropertyLabel name={propName} />}>
9384
<Flex css={{ gap: theme.spacing[3] }} direction="column" justify="center">
9485
<BindingControl>
9586
<UrlInput

Diff for: apps/builder/app/builder/features/settings-panel/controls/json.tsx

+2-11
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import {
55
type ControlProps,
66
useLocalValue,
77
VerticalLayout,
8-
Label,
98
updateExpressionValue,
109
$selectedInstanceScope,
1110
useBindingState,
12-
humanizeAttribute,
1311
} from "../shared";
1412
import {
1513
ExpressionEditor,
@@ -19,15 +17,13 @@ import {
1917
BindingControl,
2018
BindingPopover,
2119
} from "~/builder/shared/binding-popover";
20+
import { PropertyLabel } from "../property-label";
2221

2322
export const JsonControl = ({
24-
meta,
2523
prop,
2624
propName,
2725
computedValue,
28-
deletable,
2926
onChange,
30-
onDelete,
3127
}: ControlProps<"json">) => {
3228
const [error, setError] = useState<boolean>(false);
3329
const valueString = formatValue(computedValue ?? "");
@@ -50,7 +46,6 @@ export const JsonControl = ({
5046
// empty block
5147
}
5248
});
53-
const label = humanizeAttribute(meta.label || propName);
5449

5550
const { scope, aliases } = useStore($selectedInstanceScope);
5651
const expression = prop?.type === "expression" ? prop.value : valueString;
@@ -61,12 +56,8 @@ export const JsonControl = ({
6156
return (
6257
<VerticalLayout
6358
label={
64-
<Label description={meta.description} readOnly={overwritable === false}>
65-
{label}
66-
</Label>
59+
<PropertyLabel name={propName} readOnly={overwritable === false} />
6760
}
68-
deletable={deletable}
69-
onDelete={onDelete}
7061
>
7162
<BindingControl>
7263
<ExpressionEditor

Diff for: apps/builder/app/builder/features/settings-panel/controls/number.tsx

+2-12
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,19 @@ import {
99
type ControlProps,
1010
useLocalValue,
1111
ResponsiveLayout,
12-
Label,
1312
updateExpressionValue,
1413
$selectedInstanceScope,
1514
useBindingState,
1615
humanizeAttribute,
1716
} from "../shared";
17+
import { PropertyLabel } from "../property-label";
1818

1919
export const NumberControl = ({
2020
meta,
2121
prop,
2222
propName,
2323
computedValue,
2424
onChange,
25-
deletable,
26-
onDelete,
2725
}: ControlProps<"number">) => {
2826
const id = useId();
2927

@@ -56,16 +54,8 @@ export const NumberControl = ({
5654
return (
5755
<ResponsiveLayout
5856
label={
59-
<Label
60-
htmlFor={id}
61-
description={meta.description}
62-
readOnly={overwritable === false}
63-
>
64-
{label}
65-
</Label>
57+
<PropertyLabel name={propName} readOnly={overwritable === false} />
6658
}
67-
deletable={deletable}
68-
onDelete={onDelete}
6959
>
7060
<BindingControl>
7161
<InputField

Diff for: apps/builder/app/builder/features/settings-panel/controls/radio.tsx

+2-11
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ import {
1414
useBindingState,
1515
humanizeAttribute,
1616
} from "../shared";
17+
import { PropertyLabel } from "../property-label";
1718

1819
export const RadioControl = ({
1920
meta,
2021
prop,
2122
propName,
2223
computedValue,
23-
deletable,
2424
onChange,
25-
onDelete,
2625
}: ControlProps<"radio" | "inline-radio">) => {
2726
const value = computedValue === undefined ? undefined : String(computedValue);
2827
// making sure that the current value is in the list of options
@@ -43,16 +42,8 @@ export const RadioControl = ({
4342
return (
4443
<VerticalLayout
4544
label={
46-
<Label
47-
htmlFor={id}
48-
description={meta.description}
49-
readOnly={overwritable === false}
50-
>
51-
{label}
52-
</Label>
45+
<PropertyLabel name={propName} readOnly={overwritable === false} />
5346
}
54-
deletable={deletable}
55-
onDelete={onDelete}
5647
>
5748
<BindingControl>
5849
<RadioGroup

Diff for: apps/builder/app/builder/features/settings-panel/controls/resource-control.tsx

+6-24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { nanoid } from "nanoid";
12
import { useId } from "react";
23
import { useStore } from "@nanostores/react";
34
import { InputField } from "@webstudio-is/design-system";
@@ -10,22 +11,20 @@ import {
1011
import {
1112
type ControlProps,
1213
useLocalValue,
13-
ResponsiveLayout,
14-
Label,
1514
humanizeAttribute,
15+
VerticalLayout,
1616
} from "../shared";
1717
import { $resources } from "~/shared/nano-states";
1818
import { $selectedInstanceResourceScope } from "../resource-panel";
1919
import { computeExpression } from "~/shared/data-variables";
2020
import { updateWebstudioData } from "~/shared/instance-utils";
21-
import { nanoid } from "nanoid";
21+
import { PropertyLabel } from "../property-label";
2222

2323
export const ResourceControl = ({
2424
meta,
2525
prop,
2626
propName,
2727
instanceId,
28-
deletable,
2928
}: ControlProps<"resource">) => {
3029
const resources = useStore($resources);
3130
const { variableValues, scope, aliases } = useStore(
@@ -98,17 +97,6 @@ export const ResourceControl = ({
9897
});
9998
};
10099

101-
const deletePropAndResource = () => {
102-
updateWebstudioData((data) => {
103-
if (prop?.type === "resource") {
104-
data.resources.delete(prop.value);
105-
}
106-
if (prop) {
107-
data.props.delete(prop.id);
108-
}
109-
});
110-
};
111-
112100
const id = useId();
113101
const label = humanizeAttribute(meta.label || propName);
114102
let variant: BindingVariant = "bound";
@@ -122,14 +110,8 @@ export const ResourceControl = ({
122110
);
123111

124112
return (
125-
<ResponsiveLayout
126-
label={
127-
<Label htmlFor={id} description={meta.description} readOnly={readOnly}>
128-
{label}
129-
</Label>
130-
}
131-
deletable={deletable}
132-
onDelete={deletePropAndResource}
113+
<VerticalLayout
114+
label={<PropertyLabel name={propName} readOnly={readOnly} />}
133115
>
134116
<BindingControl>
135117
<InputField
@@ -156,6 +138,6 @@ export const ResourceControl = ({
156138
}
157139
/>
158140
</BindingControl>
159-
</ResponsiveLayout>
141+
</VerticalLayout>
160142
);
161143
};

0 commit comments

Comments
 (0)