Merge pull request #386 from webstudio-is/fix_default_value

Fix defaultValue to work with storybook
This commit is contained in:
Ivan Starkov authored and GitHub committed 2022-11-04 20:26:24 +04:00
commit ec047b9490
14 files changed
+140 -464

No files matched your search

@@ -53,7 +53,7 @@ const getPropsWithDefaultValue = (
.filter(([_, value]) => value.defaultValue != null)
.map(([prop, propObj]) => {
const { defaultValue } = propObj;
const value = "value" in defaultValue ? defaultValue.value : defaultValue;
const value = defaultValue;
return {
id: ObjectId().toString(),
prop,
+20 -7
View File
@@ -31,6 +31,7 @@ export const propsToArgTypes = (
}
const control = mapControlForType(prop);
result[propName] = { ...prop, ...control };
return result;
}, {} as ArgTypes);
@@ -47,6 +48,8 @@ export const mapControlForType = (propItem: PropItem) => {
return undefined;
}
const overrides = { defaultValue: propItem.defaultValue?.value ?? null };
// args that end with background or color e.g. iconColor
if (matchers.color && matchers.color.test(name)) {
const controlType = propItem.type.name;
@@ -54,26 +57,35 @@ export const mapControlForType = (propItem: PropItem) => {
if (controlType === "string") {
return {
control: { type: "color" },
defaultValue: propItem.defaultValue?.value,
...overrides,
};
}
}
// args that end with date e.g. purchaseDate
if (matchers.date && matchers.date.test(name)) {
return { control: { type: "date" } };
return {
control: { type: "date" },
...overrides,
};
}
switch (type?.name) {
case "array":
return { control: { type: "object" } };
return {
control: { type: "object" },
...overrides,
};
case "boolean":
case "Booleanish":
return { control: { type: "boolean" } };
return {
control: { type: "boolean" },
...overrides,
};
case "string":
return { control: { type: "text" } };
return { control: { type: "text" }, ...overrides };
case "number":
return { control: { type: "number" } };
return { control: { type: "number" }, ...overrides };
case "enum": {
const { value } = type;
// Remove additional quotes from enum values
@@ -82,12 +94,13 @@ export const mapControlForType = (propItem: PropItem) => {
return {
control: { type: values?.length <= 5 ? "radio" : "select" },
options: values,
...overrides,
};
}
case "function":
case "symbol":
return null;
default:
return { control: { type: "text" } };
return { control: { type: "text" }, ...overrides };
}
};
@@ -447,10 +447,7 @@
"control": {
"type": "radio"
},
"options": [
"yes",
"no"
]
"options": ["yes", "no"]
},
"radioGroup": {
"defaultValue": null,
@@ -739,6 +736,7 @@
}
},
"color": {
"defaultValue": null,
"description": "",
"name": "color",
"parent": {
@@ -943,10 +941,7 @@
"control": {
"type": "radio"
},
"options": [
"on",
"off"
]
"options": ["on", "off"]
},
"inputMode": {
"defaultValue": null,
@@ -1109,12 +1104,7 @@
"control": {
"type": "radio"
},
"options": [
"list",
"none",
"inline",
"both"
]
"options": ["list", "none", "inline", "both"]
},
"aria-busy": {
"defaultValue": null,
@@ -1378,14 +1368,7 @@
"control": {
"type": "select"
},
"options": [
"link",
"none",
"copy",
"execute",
"move",
"popup"
]
"options": ["link", "none", "copy", "execute", "move", "popup"]
},
"aria-errormessage": {
"defaultValue": null,
@@ -1662,11 +1645,7 @@
"control": {
"type": "radio"
},
"options": [
"off",
"assertive",
"polite"
]
"options": ["off", "assertive", "polite"]
},
"aria-modal": {
"defaultValue": null,
@@ -1764,10 +1743,7 @@
"control": {
"type": "radio"
},
"options": [
"horizontal",
"vertical"
]
"options": ["horizontal", "vertical"]
},
"aria-owns": {
"defaultValue": null,
@@ -2136,12 +2112,7 @@
"control": {
"type": "radio"
},
"options": [
"none",
"ascending",
"descending",
"other"
]
"options": ["none", "ascending", "descending", "other"]
},
"aria-valuemax": {
"defaultValue": null,
@@ -447,10 +447,7 @@
"control": {
"type": "radio"
},
"options": [
"yes",
"no"
]
"options": ["yes", "no"]
},
"radioGroup": {
"defaultValue": null,
@@ -739,6 +736,7 @@
}
},
"color": {
"defaultValue": null,
"description": "",
"name": "color",
"parent": {
@@ -943,10 +941,7 @@
"control": {
"type": "radio"
},
"options": [
"on",
"off"
]
"options": ["on", "off"]
},
"inputMode": {
"defaultValue": null,
@@ -1109,12 +1104,7 @@
"control": {
"type": "radio"
},
"options": [
"list",
"none",
"inline",
"both"
]
"options": ["list", "none", "inline", "both"]
},
"aria-busy": {
"defaultValue": null,
@@ -1378,14 +1368,7 @@
"control": {
"type": "select"
},
"options": [
"link",
"none",
"copy",
"execute",
"move",
"popup"
]
"options": ["link", "none", "copy", "execute", "move", "popup"]
},
"aria-errormessage": {
"defaultValue": null,
@@ -1662,11 +1645,7 @@
"control": {
"type": "radio"
},
"options": [
"off",
"assertive",
"polite"
]
"options": ["off", "assertive", "polite"]
},
"aria-modal": {
"defaultValue": null,
@@ -1764,10 +1743,7 @@
"control": {
"type": "radio"
},
"options": [
"horizontal",
"vertical"
]
"options": ["horizontal", "vertical"]
},
"aria-owns": {
"defaultValue": null,
@@ -2136,12 +2112,7 @@
"control": {
"type": "radio"
},
"options": [
"none",
"ascending",
"descending",
"other"
]
"options": ["none", "ascending", "descending", "other"]
},
"aria-valuemax": {
"defaultValue": null,
@@ -447,10 +447,7 @@
"control": {
"type": "radio"
},
"options": [
"yes",
"no"
]
"options": ["yes", "no"]
},
"radioGroup": {
"defaultValue": null,
@@ -739,6 +736,7 @@
}
},
"color": {
"defaultValue": null,
"description": "",
"name": "color",
"parent": {
@@ -943,10 +941,7 @@
"control": {
"type": "radio"
},
"options": [
"on",
"off"
]
"options": ["on", "off"]
},
"inputMode": {
"defaultValue": null,
@@ -1109,12 +1104,7 @@
"control": {
"type": "radio"
},
"options": [
"list",
"none",
"inline",
"both"
]
"options": ["list", "none", "inline", "both"]
},
"aria-busy": {
"defaultValue": null,
@@ -1378,14 +1368,7 @@
"control": {
"type": "select"
},
"options": [
"link",
"none",
"copy",
"execute",
"move",
"popup"
]
"options": ["link", "none", "copy", "execute", "move", "popup"]
},
"aria-errormessage": {
"defaultValue": null,
@@ -1662,11 +1645,7 @@
"control": {
"type": "radio"
},
"options": [
"off",
"assertive",
"polite"
]
"options": ["off", "assertive", "polite"]
},
"aria-modal": {
"defaultValue": null,
@@ -1764,10 +1743,7 @@
"control": {
"type": "radio"
},
"options": [
"horizontal",
"vertical"
]
"options": ["horizontal", "vertical"]
},
"aria-owns": {
"defaultValue": null,
@@ -2136,12 +2112,7 @@
"control": {
"type": "radio"
},
"options": [
"none",
"ascending",
"descending",
"other"
]
"options": ["none", "ascending", "descending", "other"]
},
"aria-valuemax": {
"defaultValue": null,
@@ -2232,9 +2203,7 @@
}
},
"tag": {
"defaultValue": {
"value": "div"
},
"defaultValue": "div",
"description": "",
"name": "tag",
"declarations": [
@@ -264,9 +264,7 @@
}
},
"type": {
"defaultValue": {
"value": "submit"
},
"defaultValue": "submit",
"description": "",
"name": "type",
"parent": {
@@ -298,11 +296,7 @@
"control": {
"type": "radio"
},
"options": [
"button",
"submit",
"reset"
]
"options": ["button", "submit", "reset"]
},
"value": {
"defaultValue": null,
@@ -708,10 +702,7 @@
"control": {
"type": "radio"
},
"options": [
"yes",
"no"
]
"options": ["yes", "no"]
},
"radioGroup": {
"defaultValue": null,
@@ -1000,6 +991,7 @@
}
},
"color": {
"defaultValue": null,
"description": "",
"name": "color",
"parent": {
@@ -1204,10 +1196,7 @@
"control": {
"type": "radio"
},
"options": [
"on",
"off"
]
"options": ["on", "off"]
},
"inputMode": {
"defaultValue": null,
@@ -1370,12 +1359,7 @@
"control": {
"type": "radio"
},
"options": [
"list",
"none",
"inline",
"both"
]
"options": ["list", "none", "inline", "both"]
},
"aria-busy": {
"defaultValue": null,
@@ -1639,14 +1623,7 @@
"control": {
"type": "select"
},
"options": [
"link",
"none",
"copy",
"execute",
"move",
"popup"
]
"options": ["link", "none", "copy", "execute", "move", "popup"]
},
"aria-errormessage": {
"defaultValue": null,
@@ -1923,11 +1900,7 @@
"control": {
"type": "radio"
},
"options": [
"off",
"assertive",
"polite"
]
"options": ["off", "assertive", "polite"]
},
"aria-modal": {
"defaultValue": null,
@@ -2025,10 +1998,7 @@
"control": {
"type": "radio"
},
"options": [
"horizontal",
"vertical"
]
"options": ["horizontal", "vertical"]
},
"aria-owns": {
"defaultValue": null,
@@ -2397,12 +2367,7 @@
"control": {
"type": "radio"
},
"options": [
"none",
"ascending",
"descending",
"other"
]
"options": ["none", "ascending", "descending", "other"]
},
"aria-valuemax": {
"defaultValue": null,
@@ -623,10 +623,7 @@
"control": {
"type": "radio"
},
"options": [
"yes",
"no"
]
"options": ["yes", "no"]
},
"radioGroup": {
"defaultValue": null,
@@ -915,6 +912,7 @@
}
},
"color": {
"defaultValue": null,
"description": "",
"name": "color",
"parent": {
@@ -1119,10 +1117,7 @@
"control": {
"type": "radio"
},
"options": [
"on",
"off"
]
"options": ["on", "off"]
},
"inputMode": {
"defaultValue": null,
@@ -1285,12 +1280,7 @@
"control": {
"type": "radio"
},
"options": [
"list",
"none",
"inline",
"both"
]
"options": ["list", "none", "inline", "both"]
},
"aria-busy": {
"defaultValue": null,
@@ -1554,14 +1544,7 @@
"control": {
"type": "select"
},
"options": [
"link",
"none",
"copy",
"execute",
"move",
"popup"
]
"options": ["link", "none", "copy", "execute", "move", "popup"]
},
"aria-errormessage": {
"defaultValue": null,
@@ -1838,11 +1821,7 @@
"control": {
"type": "radio"
},
"options": [
"off",
"assertive",
"polite"
]
"options": ["off", "assertive", "polite"]
},
"aria-modal": {
"defaultValue": null,
@@ -1940,10 +1919,7 @@
"control": {
"type": "radio"
},
"options": [
"horizontal",
"vertical"
]
"options": ["horizontal", "vertical"]
},
"aria-owns": {
"defaultValue": null,
@@ -2312,12 +2288,7 @@
"control": {
"type": "radio"
},
"options": [
"none",
"ascending",
"descending",
"other"
]
"options": ["none", "ascending", "descending", "other"]
},
"aria-valuemax": {
"defaultValue": null,
@@ -447,10 +447,7 @@
"control": {
"type": "radio"
},
"options": [
"yes",
"no"
]
"options": ["yes", "no"]
},
"radioGroup": {
"defaultValue": null,
@@ -739,6 +736,7 @@
}
},
"color": {
"defaultValue": null,
"description": "",
"name": "color",
"parent": {
@@ -943,10 +941,7 @@
"control": {
"type": "radio"
},
"options": [
"on",
"off"
]
"options": ["on", "off"]
},
"inputMode": {
"defaultValue": null,
@@ -1109,12 +1104,7 @@
"control": {
"type": "radio"
},
"options": [
"list",
"none",
"inline",
"both"
]
"options": ["list", "none", "inline", "both"]
},
"aria-busy": {
"defaultValue": null,
@@ -1378,14 +1368,7 @@
"control": {
"type": "select"
},
"options": [
"link",
"none",
"copy",
"execute",
"move",
"popup"
]
"options": ["link", "none", "copy", "execute", "move", "popup"]
},
"aria-errormessage": {
"defaultValue": null,
@@ -1662,11 +1645,7 @@
"control": {
"type": "radio"
},
"options": [
"off",
"assertive",
"polite"
]
"options": ["off", "assertive", "polite"]
},
"aria-modal": {
"defaultValue": null,
@@ -1764,10 +1743,7 @@
"control": {
"type": "radio"
},
"options": [
"horizontal",
"vertical"
]
"options": ["horizontal", "vertical"]
},
"aria-owns": {
"defaultValue": null,
@@ -2136,12 +2112,7 @@
"control": {
"type": "radio"
},
"options": [
"none",
"ascending",
"descending",
"other"
]
"options": ["none", "ascending", "descending", "other"]
},
"aria-valuemax": {
"defaultValue": null,
@@ -2232,9 +2203,7 @@
}
},
"tag": {
"defaultValue": {
"value": "h1"
},
"defaultValue": "h1",
"description": "",
"name": "tag",
"declarations": [
@@ -2271,13 +2240,6 @@
"control": {
"type": "select"
},
"options": [
"h1",
"h2",
"h3",
"h4",
"h5",
"h6"
]
"options": ["h1", "h2", "h3", "h4", "h5", "h6"]
}
}
@@ -66,9 +66,7 @@
}
},
"alt": {
"defaultValue": {
"value": ""
},
"defaultValue": "",
"description": "",
"name": "alt",
"parent": {
@@ -160,9 +158,7 @@
"options": ["async", "auto", "sync"]
},
"height": {
"defaultValue": {
"value": "auto"
},
"defaultValue": null,
"description": "",
"name": "height",
"parent": {
@@ -184,9 +180,7 @@
}
},
"loading": {
"defaultValue": {
"value": "lazy"
},
"defaultValue": "lazy",
"description": "",
"name": "loading",
"parent": {
@@ -303,9 +297,7 @@
}
},
"src": {
"defaultValue": {
"value": ""
},
"defaultValue": "",
"description": "",
"name": "src",
"parent": {
@@ -371,9 +363,7 @@
}
},
"width": {
"defaultValue": {
"value": "auto"
},
"defaultValue": null,
"description": "",
"name": "width",
"parent": {
@@ -1065,6 +1055,7 @@
}
},
"color": {
"defaultValue": null,
"description": "",
"name": "color",
"parent": {
@@ -2529,5 +2520,23 @@
"control": {
"type": "text"
}
},
"quality": {
"defaultValue": 80,
"description": "",
"name": "quality",
"declarations": [
{
"fileName": "src/components/image.tsx",
"name": "TypeLiteral"
}
],
"required": false,
"type": {
"name": "number"
},
"control": {
"type": "number"
}
}
}
@@ -330,15 +330,7 @@
"control": {
"type": "select"
},
"options": [
"enter",
"done",
"go",
"next",
"previous",
"search",
"send"
]
"options": ["enter", "done", "go", "next", "previous", "search", "send"]
},
"formAction": {
"defaultValue": null,
@@ -1206,10 +1198,7 @@
"control": {
"type": "radio"
},
"options": [
"yes",
"no"
]
"options": ["yes", "no"]
},
"radioGroup": {
"defaultValue": null,
@@ -1498,6 +1487,7 @@
}
},
"color": {
"defaultValue": null,
"description": "",
"name": "color",
"parent": {
@@ -1702,10 +1692,7 @@
"control": {
"type": "radio"
},
"options": [
"on",
"off"
]
"options": ["on", "off"]
},
"inputMode": {
"defaultValue": null,
@@ -1868,12 +1855,7 @@
"control": {
"type": "radio"
},
"options": [
"list",
"none",
"inline",
"both"
]
"options": ["list", "none", "inline", "both"]
},
"aria-busy": {
"defaultValue": null,
@@ -2137,14 +2119,7 @@
"control": {
"type": "select"
},
"options": [
"link",
"none",
"copy",
"execute",
"move",
"popup"
]
"options": ["link", "none", "copy", "execute", "move", "popup"]
},
"aria-errormessage": {
"defaultValue": null,
@@ -2421,11 +2396,7 @@
"control": {
"type": "radio"
},
"options": [
"off",
"assertive",
"polite"
]
"options": ["off", "assertive", "polite"]
},
"aria-modal": {
"defaultValue": null,
@@ -2523,10 +2494,7 @@
"control": {
"type": "radio"
},
"options": [
"horizontal",
"vertical"
]
"options": ["horizontal", "vertical"]
},
"aria-owns": {
"defaultValue": null,
@@ -2895,12 +2863,7 @@
"control": {
"type": "radio"
},
"options": [
"none",
"ascending",
"descending",
"other"
]
"options": ["none", "ascending", "descending", "other"]
},
"aria-valuemax": {
"defaultValue": null,
@@ -447,10 +447,7 @@
"control": {
"type": "radio"
},
"options": [
"yes",
"no"
]
"options": ["yes", "no"]
},
"radioGroup": {
"defaultValue": null,
@@ -739,6 +736,7 @@
}
},
"color": {
"defaultValue": null,
"description": "",
"name": "color",
"parent": {
@@ -943,10 +941,7 @@
"control": {
"type": "radio"
},
"options": [
"on",
"off"
]
"options": ["on", "off"]
},
"inputMode": {
"defaultValue": null,
@@ -1109,12 +1104,7 @@
"control": {
"type": "radio"
},
"options": [
"list",
"none",
"inline",
"both"
]
"options": ["list", "none", "inline", "both"]
},
"aria-busy": {
"defaultValue": null,
@@ -1378,14 +1368,7 @@
"control": {
"type": "select"
},
"options": [
"link",
"none",
"copy",
"execute",
"move",
"popup"
]
"options": ["link", "none", "copy", "execute", "move", "popup"]
},
"aria-errormessage": {
"defaultValue": null,
@@ -1662,11 +1645,7 @@
"control": {
"type": "radio"
},
"options": [
"off",
"assertive",
"polite"
]
"options": ["off", "assertive", "polite"]
},
"aria-modal": {
"defaultValue": null,
@@ -1764,10 +1743,7 @@
"control": {
"type": "radio"
},
"options": [
"horizontal",
"vertical"
]
"options": ["horizontal", "vertical"]
},
"aria-owns": {
"defaultValue": null,
@@ -2136,12 +2112,7 @@
"control": {
"type": "radio"
},
"options": [
"none",
"ascending",
"descending",
"other"
]
"options": ["none", "ascending", "descending", "other"]
},
"aria-valuemax": {
"defaultValue": null,
@@ -88,9 +88,7 @@
}
},
"href": {
"defaultValue": {
"value": ""
},
"defaultValue": "",
"description": "",
"name": "href",
"declarations": [
@@ -684,10 +682,7 @@
"control": {
"type": "radio"
},
"options": [
"yes",
"no"
]
"options": ["yes", "no"]
},
"radioGroup": {
"defaultValue": null,
@@ -976,6 +971,7 @@
}
},
"color": {
"defaultValue": null,
"description": "",
"name": "color",
"parent": {
@@ -1180,10 +1176,7 @@
"control": {
"type": "radio"
},
"options": [
"on",
"off"
]
"options": ["on", "off"]
},
"inputMode": {
"defaultValue": null,
@@ -1346,12 +1339,7 @@
"control": {
"type": "radio"
},
"options": [
"list",
"none",
"inline",
"both"
]
"options": ["list", "none", "inline", "both"]
},
"aria-busy": {
"defaultValue": null,
@@ -1615,14 +1603,7 @@
"control": {
"type": "select"
},
"options": [
"link",
"none",
"copy",
"execute",
"move",
"popup"
]
"options": ["link", "none", "copy", "execute", "move", "popup"]
},
"aria-errormessage": {
"defaultValue": null,
@@ -1899,11 +1880,7 @@
"control": {
"type": "radio"
},
"options": [
"off",
"assertive",
"polite"
]
"options": ["off", "assertive", "polite"]
},
"aria-modal": {
"defaultValue": null,
@@ -2001,10 +1978,7 @@
"control": {
"type": "radio"
},
"options": [
"horizontal",
"vertical"
]
"options": ["horizontal", "vertical"]
},
"aria-owns": {
"defaultValue": null,
@@ -2373,12 +2347,7 @@
"control": {
"type": "radio"
},
"options": [
"none",
"ascending",
"descending",
"other"
]
"options": ["none", "ascending", "descending", "other"]
},
"aria-valuemax": {
"defaultValue": null,
@@ -447,10 +447,7 @@
"control": {
"type": "radio"
},
"options": [
"yes",
"no"
]
"options": ["yes", "no"]
},
"radioGroup": {
"defaultValue": null,
@@ -739,6 +736,7 @@
}
},
"color": {
"defaultValue": null,
"description": "",
"name": "color",
"parent": {
@@ -943,10 +941,7 @@
"control": {
"type": "radio"
},
"options": [
"on",
"off"
]
"options": ["on", "off"]
},
"inputMode": {
"defaultValue": null,
@@ -1109,12 +1104,7 @@
"control": {
"type": "radio"
},
"options": [
"list",
"none",
"inline",
"both"
]
"options": ["list", "none", "inline", "both"]
},
"aria-busy": {
"defaultValue": null,
@@ -1378,14 +1368,7 @@
"control": {
"type": "select"
},
"options": [
"link",
"none",
"copy",
"execute",
"move",
"popup"
]
"options": ["link", "none", "copy", "execute", "move", "popup"]
},
"aria-errormessage": {
"defaultValue": null,
@@ -1662,11 +1645,7 @@
"control": {
"type": "radio"
},
"options": [
"off",
"assertive",
"polite"
]
"options": ["off", "assertive", "polite"]
},
"aria-modal": {
"defaultValue": null,
@@ -1764,10 +1743,7 @@
"control": {
"type": "radio"
},
"options": [
"horizontal",
"vertical"
]
"options": ["horizontal", "vertical"]
},
"aria-owns": {
"defaultValue": null,
@@ -2136,12 +2112,7 @@
"control": {
"type": "radio"
},
"options": [
"none",
"ascending",
"descending",
"other"
]
"options": ["none", "ascending", "descending", "other"]
},
"aria-valuemax": {
"defaultValue": null,
@@ -447,10 +447,7 @@
"control": {
"type": "radio"
},
"options": [
"yes",
"no"
]
"options": ["yes", "no"]
},
"radioGroup": {
"defaultValue": null,
@@ -739,6 +736,7 @@
}
},
"color": {
"defaultValue": null,
"description": "",
"name": "color",
"parent": {
@@ -943,10 +941,7 @@
"control": {
"type": "radio"
},
"options": [
"on",
"off"
]
"options": ["on", "off"]
},
"inputMode": {
"defaultValue": null,
@@ -1109,12 +1104,7 @@
"control": {
"type": "radio"
},
"options": [
"list",
"none",
"inline",
"both"
]
"options": ["list", "none", "inline", "both"]
},
"aria-busy": {
"defaultValue": null,
@@ -1378,14 +1368,7 @@
"control": {
"type": "select"
},
"options": [
"link",
"none",
"copy",
"execute",
"move",
"popup"
]
"options": ["link", "none", "copy", "execute", "move", "popup"]
},
"aria-errormessage": {
"defaultValue": null,
@@ -1662,11 +1645,7 @@
"control": {
"type": "radio"
},
"options": [
"off",
"assertive",
"polite"
]
"options": ["off", "assertive", "polite"]
},
"aria-modal": {
"defaultValue": null,
@@ -1764,10 +1743,7 @@
"control": {
"type": "radio"
},
"options": [
"horizontal",
"vertical"
]
"options": ["horizontal", "vertical"]
},
"aria-owns": {
"defaultValue": null,
@@ -2136,12 +2112,7 @@
"control": {
"type": "radio"
},
"options": [
"none",
"ascending",
"descending",
"other"
]
"options": ["none", "ascending", "descending", "other"]
},
"aria-valuemax": {
"defaultValue": null,