Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
Outline style property (#1630)
Oleg Isonenb4b86a6c8994
diff --git a/apps/builder/app/builder/features/style-panel/sections/index.ts b/apps/builder/app/builder/features/style-panel/sections/index.tsindex 4a7932febb..64fffc8488 100644--- a/apps/builder/app/builder/features/style-panel/sections/index.ts+++ b/apps/builder/app/builder/features/style-panel/sections/index.ts@@ -7,3 +7,4 @@ export * from "./position/position";export * from "./typography/typography";export * from "./backgrounds/backgrounds";export * from "./borders/borders";+export * from "./outline/outline";diff --git a/apps/builder/app/builder/features/style-panel/sections/outline/outline-offset.tsx b/apps/builder/app/builder/features/style-panel/sections/outline/outline-offset.tsxnew file mode 100644index 0000000000..8a7d2b221a--- /dev/null+++ b/apps/builder/app/builder/features/style-panel/sections/outline/outline-offset.tsx@@ -0,0 +1,59 @@+import type { StyleProperty, UnitValue } from "@webstudio-is/css-data";+import { Grid, theme } from "@webstudio-is/design-system";+import { CssValueInputContainer } from "../../controls/position/css-value-input-container";+import type { RenderCategoryProps } from "../../style-sections";+import { PropertyName } from "../../shared/property-name";+import { styleConfigByName } from "../../shared/configs";+import { getStyleSource } from "../../shared/style-info";++const property: StyleProperty = "outlineOffset";+const defaultOutlineOffsetValue: UnitValue = {+ type: "unit",+ value: 0,+ unit: "number",+};++export const OutlineOffset = (+ props: Pick<+ RenderCategoryProps,+ "currentStyle" | "setProperty" | "deleteProperty"+ >+) => {+ const { deleteProperty, setProperty, currentStyle } = props;+ const outlineOffsetValue =+ currentStyle[property]?.value ?? defaultOutlineOffsetValue;+ const outlineOffsetStyleConfig = styleConfigByName(property);+ const outlineOffsetWidthKeywords = outlineOffsetStyleConfig.items.map(+ (item) => ({+ type: "keyword" as const,+ value: item.name,+ })+ );++ return (+ <Grid+ css={{+ gridTemplateColumns: `1fr ${theme.spacing[20]}`,+ }}+ gap={2}+ >+ <PropertyName+ property={property}+ style={props.currentStyle}+ label={"Offset"}+ onReset={() => deleteProperty(property)}+ />++ <CssValueInputContainer+ key={property}+ property={property}+ label={outlineOffsetStyleConfig?.label || ""}+ styleSource={getStyleSource(currentStyle[property])}+ keywords={outlineOffsetWidthKeywords}+ setValue={setProperty(property)}+ deleteProperty={deleteProperty}+ value={outlineOffsetValue}+ />+ </Grid>+ );+};diff --git a/apps/builder/app/builder/features/style-panel/sections/outline/outline-style.tsx b/apps/builder/app/builder/features/style-panel/sections/outline/outline-style.tsxnew file mode 100644index 0000000000..06ffa6a2fa--- /dev/null+++ b/apps/builder/app/builder/features/style-panel/sections/outline/outline-style.tsx@@ -0,0 +1,75 @@+import type { StyleProperty } from "@webstudio-is/css-data";+import {+ Grid,+ theme,+ ToggleGroup,+ ToggleGroupItem,+ Tooltip,+} from "@webstudio-is/design-system";+import {+ DashBorderIcon,+ DashedBorderIcon,+ DottedBorderIcon,+ SmallXIcon,+} from "@webstudio-is/icons";+import type { RenderCategoryProps } from "../../style-sections";+import { toPascalCase } from "../../shared/keyword-utils";+import { PropertyName } from "../../shared/property-name";+import { toValue } from "@webstudio-is/css-engine";++const property: StyleProperty = "outlineStyle";+const outlineStyleValues = [+ { value: "none", Icon: SmallXIcon },+ { value: "solid", Icon: DashBorderIcon },+ { value: "dashed", Icon: DashedBorderIcon },+ { value: "dotted", Icon: DottedBorderIcon },+];++export const OutlineStyle = (+ props: Pick<+ RenderCategoryProps,+ "currentStyle" | "setProperty" | "deleteProperty"+ >+) => {+ const { currentStyle, setProperty, deleteProperty } = props;+ const outlineStyleValue = toValue(+ currentStyle["outlineStyle"]?.value ?? {+ type: "keyword",+ value: "none",+ }+ );++ return (+ <Grid+ css={{+ gridTemplateColumns: `1fr ${theme.spacing[20]} ${theme.spacing[12]}`,+ }}+ gap={2}+ >+ <PropertyName+ property={property}+ style={props.currentStyle}+ label={"Style"}+ onReset={() => deleteProperty(property)}+ />++ <ToggleGroup+ css={{+ gridColumn: `span 2`,+ justifySelf: "end",+ }}+ type="single"+ value={outlineStyleValue}+ onValueChange={(value) => setProperty(property)(value)}+ >+ {outlineStyleValues.map(({ value, Icon }) => (+ <ToggleGroupItem key={value} value={value}>+ <Tooltip content={toPascalCase(value)}>+ <Icon />+ </Tooltip>+ </ToggleGroupItem>+ ))}+ </ToggleGroup>+ </Grid>+ );+};diff --git a/apps/builder/app/builder/features/style-panel/sections/outline/outline-width.tsx b/apps/builder/app/builder/features/style-panel/sections/outline/outline-width.tsxnew file mode 100644index 0000000000..ea4525f410--- /dev/null+++ b/apps/builder/app/builder/features/style-panel/sections/outline/outline-width.tsx@@ -0,0 +1,51 @@+import type { StyleProperty } from "@webstudio-is/css-data";+import { Grid, theme } from "@webstudio-is/design-system";+import type { RenderCategoryProps } from "../../style-sections";+import { PropertyName } from "../../shared/property-name";+import { CssValueInputContainer } from "../../controls/position/css-value-input-container";+import { styleConfigByName } from "../../shared/configs";+import { getStyleSource } from "../../shared/style-info";++const property: StyleProperty = "outlineWidth";++export const OutlineWidth = (+ props: Pick<+ RenderCategoryProps,+ "currentStyle" | "setProperty" | "deleteProperty"+ >+) => {+ const { deleteProperty, setProperty, currentStyle } = props;+ const outlineWidthValue = currentStyle[property]?.value;+ const outlineStyleConfig = styleConfigByName(property);+ const outlineStyleWidthKeywords = outlineStyleConfig.items.map((item) => ({+ type: "keyword" as const,+ value: item.name,+ }));++ return (+ <Grid+ css={{+ gridTemplateColumns: `1fr ${theme.spacing[20]}`,+ }}+ gap={2}+ >+ <PropertyName+ property={property}+ style={props.currentStyle}+ label={"Width"}+ onReset={() => deleteProperty(property)}+ />++ <CssValueInputContainer+ key={property}+ property={property}+ label={outlineStyleConfig?.label || ""}+ styleSource={getStyleSource(currentStyle[property])}+ keywords={outlineStyleWidthKeywords}+ setValue={setProperty(property)}+ deleteProperty={deleteProperty}+ value={outlineWidthValue}+ />+ </Grid>+ );+};diff --git a/apps/builder/app/builder/features/style-panel/sections/outline/outline.tsx b/apps/builder/app/builder/features/style-panel/sections/outline/outline.tsxnew file mode 100644index 0000000000..853bd4b409--- /dev/null+++ b/apps/builder/app/builder/features/style-panel/sections/outline/outline.tsx@@ -0,0 +1,76 @@+import { Flex, Grid, theme, Box } from "@webstudio-is/design-system";+import type { StyleProperty } from "@webstudio-is/css-data";+import { ColorControl } from "../../controls";+import { CollapsibleSection } from "../../shared/collapsible-section";+import type { RenderCategoryProps } from "../../style-sections";+import { OutlineStyle } from "./outline-style";+import { PropertyName } from "../../shared/property-name";+import { OutlineWidth } from "./outline-width";+import { OutlineOffset } from "./outline-offset";++const property: StyleProperty = "outlineColor";+const properties: StyleProperty[] = [+ "outlineStyle",+ "outlineColor",+ "outlineWidth",+ "outlineOffset",+];++export const OutlineSection = (props: RenderCategoryProps) => {+ const { currentStyle, setProperty, deleteProperty } = props;++ return (+ <CollapsibleSection+ label="Outline"+ currentStyle={currentStyle}+ properties={properties}+ >+ <Flex direction="column" gap={2}>+ <OutlineStyle+ currentStyle={currentStyle}+ setProperty={setProperty}+ deleteProperty={deleteProperty}+ />++ <Grid+ css={{+ gridTemplateColumns: `1fr ${theme.spacing[20]} ${theme.spacing[12]}`,+ }}+ gapX={2}+ >+ <PropertyName+ style={currentStyle}+ property={property}+ label={"Color"}+ onReset={() => deleteProperty(property)}+ />++ <Box+ css={{+ gridColumn: `span 2`,+ }}+ >+ <ColorControl+ property={property}+ currentStyle={currentStyle}+ setProperty={setProperty}+ deleteProperty={deleteProperty}+ />+ </Box>+ </Grid>++ <OutlineWidth+ currentStyle={currentStyle}+ setProperty={setProperty}+ deleteProperty={deleteProperty}+ />++ <OutlineOffset+ currentStyle={currentStyle}+ setProperty={setProperty}+ deleteProperty={deleteProperty}+ />+ </Flex>+ </CollapsibleSection>+ );+};diff --git a/apps/builder/app/builder/features/style-panel/shared/style-info.ts b/apps/builder/app/builder/features/style-panel/shared/style-info.tsindex 260450f3f0..2f714c65d1 100644--- a/apps/builder/app/builder/features/style-panel/shared/style-info.ts+++ b/apps/builder/app/builder/features/style-panel/shared/style-info.ts@@ -60,6 +60,15 @@ type SourceProperties = {[property in StyleProperty]?: SourceValueInfo;};+/*+ * For some cases we are encouraging to use custom defaults, than+ * `initial` values provided by browsers. This helps in controlling the behaviour+ * of such properties+ */+const CUSTOM_DEFAULT_VALUES: Partial<Record<StyleProperty, StyleValue>> = {+ outlineWidth: { value: 0, type: "unit", unit: "px" },+};+export type StyleValueInfo = {value: StyleValue;local?: StyleValue;@@ -559,6 +568,7 @@ export const useStyleInfo = () => {const computed = browserStyle?.[property];const defaultValue =htmlStyle?.[property] ??+ CUSTOM_DEFAULT_VALUES[property] ??properties[property as keyof typeof properties].initial;const preset = presetStyle?.[property];const inherited = inheritedInfo[property];diff --git a/apps/builder/app/builder/features/style-panel/style-sections.tsx b/apps/builder/app/builder/features/style-panel/style-sections.tsxindex 659114033d..e431502ca8 100644--- a/apps/builder/app/builder/features/style-panel/style-sections.tsx+++ b/apps/builder/app/builder/features/style-panel/style-sections.tsx@@ -20,6 +20,7 @@ import {TypographySection,BackgroundsSection,BordersSection,+ OutlineSection,} from "./sections";export const categories = [@@ -32,6 +33,7 @@ export const categories = ["typography","backgrounds","borders",+ "outline",];export type Category = (typeof categories)[number];@@ -137,4 +139,5 @@ export const sections: {typography: TypographySection,backgrounds: BackgroundsSection,borders: BordersSection,+ outline: OutlineSection,};diff --git a/apps/builder/app/dashboard/projects/project-card.tsx b/apps/builder/app/dashboard/projects/project-card.tsxindex 708625918a..cd17a0904d 100644--- a/apps/builder/app/dashboard/projects/project-card.tsx+++ b/apps/builder/app/dashboard/projects/project-card.tsx@@ -44,6 +44,7 @@ const containerStyle = css({const thumbnailStyle = css({position: "relative",overflow: "hidden",+ minWidth: "100%",});const footerStyle = css({diff --git a/packages/css-data/bin/mdn-data.ts b/packages/css-data/bin/mdn-data.tsindex 46d988ca26..f0fc736382 100755--- a/packages/css-data/bin/mdn-data.ts+++ b/packages/css-data/bin/mdn-data.ts@@ -56,7 +56,13 @@ const normalizedValues = {} as const;const beautifyKeyword = (property: string, keyword: string) => {- if (keyword === "currentcolor") {+ /*+ * The default value is `invert` or `currentcolor` for some css properties.+ * But that isn't supported in all browsers, example outline-color.+ * So, going with currentColor for consistency.+ * https://developer.mozilla.org/en-US/docs/Web/CSS/outline-color#formal_definition+ */+ if (keyword === "currentcolor" || keyword === "invertOrCurrentColor") {return "currentColor";}// builder style panel cannot interpret "normal" and "bold"diff --git a/packages/css-data/src/__generated__/properties.ts b/packages/css-data/src/__generated__/properties.tsindex da224431c9..0ced72ff2a 100644--- a/packages/css-data/src/__generated__/properties.ts+++ b/packages/css-data/src/__generated__/properties.ts@@ -2365,7 +2365,7 @@ export const properties = {inherited: false,initial: {type: "keyword",- value: "invertOrCurrentColor",+ value: "currentColor",},popularity: 0.09538741,appliesTo: "allElements",diff --git a/packages/react-sdk/src/css/normalize.ts b/packages/react-sdk/src/css/normalize.tsindex 8dce2ac7ce..5e91dae0fe 100644--- a/packages/react-sdk/src/css/normalize.ts+++ b/packages/react-sdk/src/css/normalize.ts@@ -16,7 +16,7 @@*/// webstudio custom opinionated presets-import { borders } from "./presets";+import { borders, outline } from "./presets";import type { EmbedTemplateStyleDecl } from "../embed-template";export type Styles = EmbedTemplateStyleDecl[];@@ -37,7 +37,7 @@ const boxSizing = {* box-sizing: border-box;}*/-const baseStyle = [boxSizing, ...borders] satisfies Styles;+const baseStyle = [boxSizing, ...borders, ...outline] satisfies Styles;export const div = baseStyle;export const address = baseStyle;diff --git a/packages/react-sdk/src/css/presets.ts b/packages/react-sdk/src/css/presets.tsindex 4658a7a843..fc2c86f822 100644--- a/packages/react-sdk/src/css/presets.ts+++ b/packages/react-sdk/src/css/presets.ts@@ -18,3 +18,10 @@ export const borders: Styles = [value: { type: "unit", value: 1, unit: "px" },},];++export const outline: Styles = [+ {+ property: "outlineWidth",+ value: { type: "unit", value: 1, unit: "px" },+ },+];