Skip to content

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.

Breakpoints editor (#1543)

Oleg Isonen1962ba89b9bd
diff --git a/apps/builder/app/builder/features/breakpoints/breakpoints-editor.tsx b/apps/builder/app/builder/features/breakpoints/breakpoints-editor.tsx
index 69d91ead0c..aad0098f96 100644
--- a/apps/builder/app/builder/features/breakpoints/breakpoints-editor.tsx
+++ b/apps/builder/app/builder/features/breakpoints/breakpoints-editor.tsx
@@ -1,95 +1,145 @@
-import { useState } from "react";
-import { useDebouncedCallback } from "use-debounce";
+import { Fragment, useEffect, useRef, useState } from "react";
import { nanoid } from "nanoid";
import store from "immerhin";
import type { Breakpoint } from "@webstudio-is/project-build";
import {
theme,
- Button,
- DeprecatedTextField,
Flex,
- DeprecatedText2,
+ PanelTitle,
+ Select,
+ IconButton,
+ InputField,
+ Text,
+ PopoverSeparator,
+ Separator,
+ Box,
} from "@webstudio-is/design-system";
-import { PlusIcon, TrashIcon } from "@webstudio-is/icons";
+import { MinusIcon, PlusIcon } from "@webstudio-is/icons";
import { breakpointsStore } from "~/shared/nano-states";
import { useStore } from "@nanostores/react";
+import { groupBreakpoints, isBaseBreakpoint } from "~/shared/breakpoints";
+import { z } from "zod";
type BreakpointEditorItemProps = {
breakpoint: Breakpoint;
- onChange: (breakpoint: Breakpoint) => void;
+ autoFocus?: boolean;
+ onChangeComplete: (breakpoint: Breakpoint) => void;
onDelete: (breakpoint: Breakpoint) => void;
};
+const BreakpointFormData = z.object({
+ label: z.string(),
+ type: z.enum(["minWidth", "maxWidth"]),
+ value: z.string().transform(Number),
+});
+
+const useHandleChangeComplete = (
+ breakpoint: Breakpoint,
+ onChangeComplete: (breakpoint: Breakpoint) => void
+) => {
+ const formRef = useRef<HTMLFormElement>(null);
+ const handleChangeComplete = () => {
+ const form = formRef.current;
+ if (form === null || form.reportValidity() === false) {
+ return;
+ }
+ const parsed = BreakpointFormData.safeParse(
+ Object.fromEntries(new FormData(form))
+ );
+ // Should never be not successful because the html validator should catch it
+ if (parsed.success) {
+ const newBreakpoint: Breakpoint = {
+ id: breakpoint.id,
+ label: parsed.data.label,
+ [parsed.data.type]: parsed.data.value,
+ };
+ onChangeComplete(newBreakpoint);
+ }
+ };
+ const handleChangeCompleteRef = useRef(handleChangeComplete);
+ handleChangeCompleteRef.current = handleChangeComplete;
+
+ // Handle change when unmounting
+ useEffect(() => handleChangeCompleteRef.current, []);
+
+ return { formRef, handleChangeComplete };
+};
+
const BreakpointEditorItem = ({
- breakpoint: initialBreakpoint,
- onChange,
+ breakpoint,
+ autoFocus,
+ onChangeComplete,
onDelete,
}: BreakpointEditorItemProps) => {
- const [breakpoint, setBreakpoint] = useState(initialBreakpoint);
-
- const handleChangeBreakpointDebounced = useDebouncedCallback(
- (nextBreakpoint: Breakpoint) => {
- if (nextBreakpoint !== initialBreakpoint) {
- onChange(nextBreakpoint);
- }
- },
- 500
+ const { formRef, handleChangeComplete } = useHandleChangeComplete(
+ breakpoint,
+ onChangeComplete
);
-
return (
- <form
- onKeyDown={(event) => {
- event.stopPropagation();
- }}
- onChange={(event) => {
- event.stopPropagation();
- const form = event.currentTarget;
- if (form.reportValidity() === false) {
- return;
- }
- const data = new FormData(form);
- const nextBreakpoint: Breakpoint = {
- ...breakpoint,
- label: String(data.get("label")),
- minWidth: Number(data.get("minWidth")),
- };
- setBreakpoint(nextBreakpoint);
- handleChangeBreakpointDebounced(nextBreakpoint);
- }}
- >
- <Flex
- gap="1"
- css={{ paddingLeft: theme.spacing[10], paddingRight: theme.spacing[9] }}
+ <Flex gap="2" css={{ mx: theme.spacing[7] }}>
+ <form
+ ref={formRef}
+ onKeyPress={(event) => {
+ if (event.key === "Enter") {
+ handleChangeComplete();
+ }
+ }}
+ onSubmit={(event) => {
+ event.preventDefault();
+ handleChangeComplete();
+ }}
+ onBlur={handleChangeComplete}
>
- <DeprecatedTextField
- css={{ width: 100, flexGrow: 1 }}
- type="text"
- variant="ghost"
- defaultValue={breakpoint.label}
- placeholder="Breakpoint name"
- name="label"
- minLength={2}
- required
- />
- <DeprecatedTextField
- css={{ textAlign: "right", width: 50 }}
- variant="ghost"
- defaultValue={breakpoint.minWidth ?? breakpoint.maxWidth ?? 0}
- type="number"
- name="minWidth"
- min={0}
- required
- />
- <Button
- type="button"
- color="ghost"
- onClick={() => {
- onDelete(breakpoint);
- }}
- prefix={<TrashIcon />}
- />
- </Flex>
- </form>
+ <Flex direction="column" gap="1">
+ <InputField
+ type="text"
+ defaultValue={breakpoint.minWidth ?? breakpoint.maxWidth ?? 0}
+ placeholder="Breakpoint name"
+ name="label"
+ minLength={1}
+ required
+ autoFocus={autoFocus}
+ />
+ <Flex gap="2" css={{ width: theme.spacing[26] }}>
+ <Select
+ name="type"
+ css={{ zIndex: theme.zIndices[1], width: theme.spacing[21] }}
+ options={["maxWidth", "minWidth"]}
+ getLabel={(option) =>
+ option === "maxWidth" ? "Max Width" : "Min Width"
+ }
+ defaultValue={breakpoint.maxWidth ? "maxWidth" : "minWidth"}
+ onChange={handleChangeComplete}
+ />
+ <InputField
+ css={{ flexShrink: 1 }}
+ defaultValue={breakpoint.minWidth ?? breakpoint.maxWidth ?? 0}
+ type="number"
+ name="value"
+ min={0}
+ required
+ suffix={
+ <Text
+ variant="unit"
+ color="subtle"
+ align="center"
+ css={{ width: theme.spacing[10] }}
+ >
+ PX
+ </Text>
+ }
+ />
+ </Flex>
+ </Flex>
+ </form>
+ <IconButton
+ onClick={() => {
+ onDelete(breakpoint);
+ }}
+ >
+ <MinusIcon />
+ </IconButton>
+ </Flex>
);
};
@@ -100,59 +150,66 @@ type BreakpointsEditorProps = {
export const BreakpointsEditor = ({ onDelete }: BreakpointsEditorProps) => {
const breakpoints = useStore(breakpointsStore);
const [addedBreakpoints, setAddedBreakpoints] = useState<Breakpoint[]>([]);
- const storedBreakpoints = new Set<string>();
- for (const breakpoint of breakpoints.values()) {
- storedBreakpoints.add(breakpoint.id);
- }
- // filter out new breakpoints which are already store
- // instead of deleting from state to avoid the case
- // when both states do not have such breakpoint
- // and focused input remounts
- const newBreakpoints = addedBreakpoints.filter(
- (breakpoint) => storedBreakpoints.has(breakpoint.id) === false
+ const initialBreakpointsRef = useRef(
+ groupBreakpoints(Array.from(breakpoints.values()))
);
+ const allBreakpoints = [
+ ...addedBreakpoints,
+ ...initialBreakpointsRef.current.filter(
+ (breakpoint) =>
+ addedBreakpoints.find((added) => added.id === breakpoint.id) ===
+ undefined
+ ),
+ ].filter((breakpoint) => isBaseBreakpoint(breakpoint) === false);
+
+ const handleChangeComplete = (breakpoint: Breakpoint) => {
+ store.createTransaction([breakpointsStore], (breakpoints) => {
+ breakpoints.set(breakpoint.id, breakpoint);
+ });
+ };
+
return (
- <Flex gap="2" direction="column">
- <Flex
- align="center"
- gap="1"
- justify="between"
+ <Flex direction="column">
+ <PanelTitle
css={{
- paddingLeft: theme.spacing[11],
- paddingRight: theme.spacing[9],
- py: theme.spacing[3],
+ px: theme.spacing[7],
}}
- >
- <DeprecatedText2>Breakpoints</DeprecatedText2>
- <Button
- color="ghost"
- onClick={() => {
- setAddedBreakpoints((prev) => [
- ...prev,
- {
+ suffix={
+ <IconButton
+ onClick={() => {
+ const newBreakpoint: Breakpoint = {
id: nanoid(),
label: "",
minWidth: 0,
- },
- ]);
- }}
- prefix={<PlusIcon />}
- />
- </Flex>
- {[...breakpoints.values(), ...newBreakpoints].map((breakpoint) => {
- return (
- <BreakpointEditorItem
- key={breakpoint.id}
- breakpoint={breakpoint}
- onChange={(updatedBreakpoint) => {
- store.createTransaction([breakpointsStore], (breakpoints) => {
- breakpoints.set(updatedBreakpoint.id, updatedBreakpoint);
- });
+ };
+ setAddedBreakpoints([newBreakpoint, ...addedBreakpoints]);
}}
- onDelete={onDelete}
- />
- );
- })}
+ >
+ <PlusIcon />
+ </IconButton>
+ }
+ >
+ {"Breakpoints"}
+ </PanelTitle>
+ <Separator />
+ <Box css={{ marginTop: theme.spacing[5] }}>
+ {allBreakpoints.map((breakpoint, index, all) => {
+ return (
+ <Fragment key={breakpoint.id}>
+ <BreakpointEditorItem
+ breakpoint={breakpoint}
+ onChangeComplete={handleChangeComplete}
+ onDelete={onDelete}
+ autoFocus={index === 0}
+ />
+ {index < all.length - 1 && <PopoverSeparator />}
+ </Fragment>
+ );
+ })}
+ </Box>
+ {allBreakpoints.length === 0 && (
+ <Text css={{ margin: theme.spacing[10] }}>No breakpoints found</Text>
+ )}
</Flex>
);
};
diff --git a/apps/builder/app/builder/features/breakpoints/breakpoints-popover.tsx b/apps/builder/app/builder/features/breakpoints/breakpoints-popover.tsx
index f7ebfeba5f..363251e909 100644
--- a/apps/builder/app/builder/features/breakpoints/breakpoints-popover.tsx
+++ b/apps/builder/app/builder/features/breakpoints/breakpoints-popover.tsx
@@ -33,9 +33,13 @@ import {
selectedBreakpointIdStore,
selectedBreakpointStore,
} from "~/shared/nano-states";
-import { isFeatureEnabled } from "@webstudio-is/feature-flags";
-import { groupBreakpoints, minCanvasWidth } from "~/shared/breakpoints";
+import {
+ groupBreakpoints,
+ isBaseBreakpoint,
+ minCanvasWidth,
+} from "~/shared/breakpoints";
import { scaleStore } from "~/builder/shared/nano-states";
+import { useSetInitialCanvasWidth } from "./use-set-initial-canvas-width";
export const BreakpointsPopover = () => {
const [view, setView] = useState<
@@ -47,6 +51,7 @@ export const BreakpointsPopover = () => {
const breakpoints = useStore(breakpointsStore);
const selectedBreakpoint = useStore(selectedBreakpointStore);
const scale = useStore(scaleStore);
+ const setInitialCanvasWidth = useSetInitialCanvasWidth();
useSubscribe("openBreakpointsMenu", () => {
setView("initial");
@@ -76,10 +81,14 @@ export const BreakpointsPopover = () => {
}
}
);
+
if (breakpointToDelete.id === selectedBreakpoint.id) {
- selectedBreakpointIdStore.set(undefined);
+ const breakpointsArray = Array.from(breakpoints.values());
+ const base =
+ breakpointsArray.find(isBaseBreakpoint) ?? breakpointsArray[0];
+ selectedBreakpointIdStore.set(base.id);
+ setInitialCanvasWidth(base.id);
}
-
setBreakpointToDelete(undefined);
setView("editor");
};
@@ -100,7 +109,7 @@ export const BreakpointsPopover = () => {
</PopoverTrigger>
<PopoverPortal>
<PopoverContent
- css={{ zIndex: theme.zIndices[1] }}
+ css={{ zIndex: theme.zIndices[1], padding: 0 }}
sideOffset={0}
collisionPadding={4}
align="start"
@@ -126,7 +135,7 @@ export const BreakpointsPopover = () => {
{view === "initial" && (
<>
<Flex
- css={{ px: theme.spacing[7], py: theme.spacing[5] }}
+ css={{ px: theme.spacing[7], paddingTop: theme.spacing[5] }}
gap="3"
>
<WidthInput min={minCanvasWidth} />
@@ -151,6 +160,7 @@ export const BreakpointsPopover = () => {
asChild
onSelect={() => {
selectedBreakpointIdStore.set(breakpoint.id);
+ setInitialCanvasWidth(breakpoint.id);
}}
index={index}
key={breakpoint.id}
@@ -167,7 +177,7 @@ export const BreakpointsPopover = () => {
>
{breakpoint.minWidth ??
breakpoint.maxWidth ??
- breakpoint.label}
+ "Base"}
</Box>
<PopoverMenuItemRightSlot
css={{ color: theme.colors.foregroundSubtle }}
@@ -187,29 +197,29 @@ export const BreakpointsPopover = () => {
</List>
</>
)}
- {isFeatureEnabled("breakpointsEditor") &&
- (view === "editor" || view === "initial") && (
- <>
- <PopoverSeparator />
- <PopoverMenuItemContainer
- css={{
- justifyContent: "center",
- px: theme.spacing[7],
+ {(view === "editor" || view === "initial") && (
+ <>
+ <PopoverSeparator />
+ <PopoverMenuItemContainer
+ css={{
+ justifyContent: "center",
+ mx: theme.spacing[7],
+ paddingBottom: theme.spacing[5],
+ }}
+ >
+ <Button
+ color="neutral"
+ css={{ flexGrow: 1 }}
+ onClick={(event) => {
+ event.preventDefault();
+ setView(view === "initial" ? "editor" : "initial");
}}
>
- <Button
- color="neutral"
- css={{ flexGrow: 1 }}
- onClick={(event) => {
- event.preventDefault();
- setView(view === "initial" ? "editor" : "initial");
- }}
- >
- {view === "editor" ? "Done" : "Edit breakpoints"}
- </Button>
- </PopoverMenuItemContainer>
- </>
- )}
+ {view === "editor" ? "Done" : "Edit breakpoints"}
+ </Button>
+ </PopoverMenuItemContainer>
+ </>
+ )}
</PopoverContent>
</PopoverPortal>
</Popover>
diff --git a/apps/builder/app/builder/features/breakpoints/breakpoints-selector.tsx b/apps/builder/app/builder/features/breakpoints/breakpoints-selector.tsx
index 5c9a9b04b0..14d72c2794 100644
--- a/apps/builder/app/builder/features/breakpoints/breakpoints-selector.tsx
+++ b/apps/builder/app/builder/features/breakpoints/breakpoints-selector.tsx
@@ -31,10 +31,7 @@ export const BreakpointsSelector = ({
value={selectedBreakpoint.id}
onValueChange={(breakpointId: string) => {
selectedBreakpointIdStore.set(breakpointId);
- const nextSelectedBreakpoint = breakpoints.get(breakpointId);
- if (nextSelectedBreakpoint) {
- setInitialCanvasWidth(nextSelectedBreakpoint.id);
- }
+ setInitialCanvasWidth(breakpointId);
}}
css={{ position: "relative" }}
>
diff --git a/apps/builder/app/builder/features/breakpoints/confirmation-dialog.tsx b/apps/builder/app/builder/features/breakpoints/confirmation-dialog.tsx
index 44914cb6ab..951365d158 100644
--- a/apps/builder/app/builder/features/breakpoints/confirmation-dialog.tsx
+++ b/apps/builder/app/builder/features/breakpoints/confirmation-dialog.tsx
@@ -37,6 +37,7 @@ export const ConfirmationDialog = ({
Delete
</Button>
<Button
+ color="neutral"
autoFocus
onClick={() => {
onAbort();
diff --git a/apps/builder/app/canvas/shared/styles.ts b/apps/builder/app/canvas/shared/styles.ts
index 7db6b13c03..3a11ce0a9c 100644
--- a/apps/builder/app/canvas/shared/styles.ts
+++ b/apps/builder/app/canvas/shared/styles.ts
@@ -34,7 +34,7 @@ import {
} from "@webstudio-is/css-engine";
import { useSubscribe } from "~/shared/pubsub";
-const cssEngine = createCssEngine({ name: "user-styles" });
+const userCssEngine = createCssEngine({ name: "user-styles" });
const helpersCssEngine = createCssEngine({ name: "helpers" });
const fontsAndDefaultsCssEngine = createCssEngine({
name: "fonts-and-defaults",
@@ -118,8 +118,9 @@ export const GlobalStyles = () => {
useIsomorphicLayoutEffect(() => {
for (const breakpoint of breakpoints.values()) {
- cssEngine.addMediaRule(breakpoint.id, breakpoint);
+ userCssEngine.addMediaRule(breakpoint.id, breakpoint);
}
+ userCssEngine.render();
}, [breakpoints]);
useIsomorphicLayoutEffect(() => {
@@ -188,10 +189,13 @@ const getOrCreateRule = ({
const key = `${instanceId}:${breakpointId}:${state}`;
let rule = wrappedRulesMap.get(key);
if (rule === undefined) {
- rule = cssEngine.addStyleRule(`[${idAttribute}="${instanceId}"]${state}`, {
- breakpoint: breakpointId,
- style: {},
- });
+ rule = userCssEngine.addStyleRule(
+ `[${idAttribute}="${instanceId}"]${state}`,
+ {
+ breakpoint: breakpointId,
+ style: {},
+ }
+ );
wrappedRulesMap.set(key, rule);
}
const params = getParams();
@@ -291,7 +295,7 @@ export const useCssRules = ({
}
}
- cssEngine.render();
+ userCssEngine.render();
}, [instanceId, selectedState, instanceStyles, breakpoints]);
};
@@ -351,6 +355,6 @@ const usePreviewStyle = () => {
}
}
- cssEngine.render();
+ userCssEngine.render();
});
};
diff --git a/apps/builder/app/shared/breakpoints/group-breakpoints.ts b/apps/builder/app/shared/breakpoints/group-breakpoints.ts
index b703b1c6ad..50b88e4ddf 100644
--- a/apps/builder/app/shared/breakpoints/group-breakpoints.ts
+++ b/apps/builder/app/shared/breakpoints/group-breakpoints.ts
@@ -7,7 +7,7 @@ export const groupBreakpoints = <
>(
breakpoints: Array<Breakpoint>
) => {
- const sorted = breakpoints.sort(compareMedia);
+ const sorted = [...breakpoints].sort(compareMedia);
const maxs = sorted.filter((breakpoint) => breakpoint.maxWidth !== undefined);
const mins = sorted
.filter((breakpoint) => breakpoint.minWidth !== undefined)
diff --git a/packages/css-engine/src/core/compare-media.test.ts b/packages/css-engine/src/core/compare-media.test.ts
index 2ae9c4838f..65e17c4d09 100644
--- a/packages/css-engine/src/core/compare-media.test.ts
+++ b/packages/css-engine/src/core/compare-media.test.ts
@@ -2,33 +2,55 @@ import { describe, test, expect } from "@jest/globals";
import { compareMedia } from "./compare-media";
describe("Compare media", () => {
- test("mobile first", () => {
+ test("min-width", () => {
const initial = [
+ {},
+ { minWidth: 1280 },
+ { minWidth: 0 },
+ { minWidth: 1024 },
+ { minWidth: 768 },
+ ];
+ const expected = [
+ {},
{ minWidth: 0 },
{ minWidth: 768 },
{ minWidth: 1024 },
{ minWidth: 1280 },
];
- expect(initial.sort(compareMedia)).toStrictEqual(initial);
+ const sorted = initial.sort(compareMedia);
+ expect(sorted).toStrictEqual(expected);
});
- test("random minWidth", () => {
- const initial = [{ minWidth: 0 }, { minWidth: 3 }, { minWidth: 2 }];
- const sorted = [{ minWidth: 0 }, { minWidth: 2 }, { minWidth: 3 }];
- expect(initial.sort(compareMedia)).toStrictEqual(sorted);
+ test("max-width", () => {
+ const initial = [
+ {},
+ { maxWidth: 1280 },
+ { maxWidth: 0 },
+ { maxWidth: 1024 },
+ { maxWidth: 768 },
+ ];
+ const expected = [
+ {},
+ { maxWidth: 1280 },
+ { maxWidth: 1024 },
+ { maxWidth: 768 },
+ { maxWidth: 0 },
+ ];
+ const sorted = initial.sort(compareMedia);
+ expect(sorted).toStrictEqual(expected);
});
- test("webflow", () => {
+ test("mixed max and min", () => {
const initial = [
{},
{ maxWidth: 991 },
- { maxWidth: 767 },
{ maxWidth: 479 },
- { minWidth: 1280 },
+ { maxWidth: 767 },
{ minWidth: 1440 },
+ { minWidth: 1280 },
{ minWidth: 1920 },
];
- const sorted = [
+ const expected = [
{},
{ maxWidth: 991 },
{ maxWidth: 767 },
@@ -37,6 +59,7 @@ describe("Compare media", () => {
{ minWidth: 1440 },
{ minWidth: 1920 },
];
- expect(initial.sort(compareMedia)).toStrictEqual(sorted);
+ const sorted = initial.sort(compareMedia);
+ expect(sorted).toStrictEqual(expected);
});
});
diff --git a/packages/css-engine/src/core/compare-media.ts b/packages/css-engine/src/core/compare-media.ts
index a023dc0a1f..fa6aad791d 100644
--- a/packages/css-engine/src/core/compare-media.ts
+++ b/packages/css-engine/src/core/compare-media.ts
@@ -9,18 +9,19 @@ export const compareMedia = (
optionB: MediaRuleOptions
) => {
// Ensures a media with no min/max is always first
- if (
- (optionA?.minWidth === undefined && optionA?.maxWidth !== undefined) ||
- (optionB?.minWidth === undefined && optionB?.maxWidth !== undefined)
- ) {
+ if (optionA.minWidth === undefined && optionA.maxWidth === undefined) {
+ return -1;
+ }
+ if (optionB.minWidth === undefined && optionB.maxWidth === undefined) {
return 1;
}
+
// Both are defined by minWidth, put the bigger one first
- if (optionA?.minWidth !== undefined && optionB?.minWidth !== undefined) {
+ if (optionA.minWidth !== undefined && optionB.minWidth !== undefined) {
return optionA.minWidth - optionB.minWidth;
}
// Both are defined by maxWidth, put the smaller one first
- if (optionA?.maxWidth !== undefined && optionB?.maxWidth !== undefined) {
+ if (optionA.maxWidth !== undefined && optionB.maxWidth !== undefined) {
return optionB.maxWidth - optionA.maxWidth;
}
diff --git a/packages/css-engine/src/core/css-engine.test.ts b/packages/css-engine/src/core/css-engine.test.ts
index 88e485b426..f7d54876ab 100644
--- a/packages/css-engine/src/core/css-engine.test.ts
+++ b/packages/css-engine/src/core/css-engine.test.ts
@@ -266,6 +266,27 @@ describe("CssEngine", () => {
`);
});
+ test("update media rule options", () => {
+ engine.addMediaRule(mediaId0, mediaRuleOptions0);
+ engine.addStyleRule(".c", {
+ style: {
+ color: { type: "keyword", value: "red" },
+ },
+ breakpoint: "0",
+ });
+ expect(engine.cssText).toMatchInlineSnapshot(`
+ "@media all and (min-width: 0px) {
+ .c { color: red }
+ }"
+ `);
+ engine.addMediaRule(mediaId0, { minWidth: 10 });
+ expect(engine.cssText).toMatchInlineSnapshot(`
+ "@media all and (min-width: 10px) {
+ .c { color: red }
+ }"
+ `);
+ });
+
test("don't override media queries", () => {
engine.addMediaRule(mediaId0, mediaRuleOptions0);
engine.addStyleRule(".c", {
diff --git a/packages/css-engine/src/core/css-engine.ts b/packages/css-engine/src/core/css-engine.ts
index f47c18cd87..6cf3c99417 100644
--- a/packages/css-engine/src/core/css-engine.ts
+++ b/packages/css-engine/src/core/css-engine.ts
@@ -39,7 +39,14 @@ export class CssEngine {
mediaRule = new MediaRule(options);
this.#mediaRules.set(id, mediaRule);
this.#isDirty = true;
+ return mediaRule;
}
+
+ if (options) {
+ mediaRule.options = options;
+ this.#isDirty = true;
+ }
+
return mediaRule;
}
addStyleRule(
diff --git a/packages/css-engine/src/core/find-applicable-media.ts b/packages/css-engine/src/core/find-applicable-media.ts
index 18d8a41c3b..bd9240364e 100644
--- a/packages/css-engine/src/core/find-applicable-media.ts
+++ b/packages/css-engine/src/core/find-applicable-media.ts
@@ -7,7 +7,7 @@ export const findApplicableMedia = <Media extends MediaRuleOptions>(
media: Array<Media>,
width: number
) => {
- const sortedMedia = media
+ const sortedMedia = [...media]
.sort(compareMedia)
// Reverse order is needed because the last rule in CSSOM has higher source order specificity.
.reverse();
diff --git a/packages/design-system/src/components/select.tsx b/packages/design-system/src/components/select.tsx
index b269e76c2d..49002a7f9b 100644
--- a/packages/design-system/src/components/select.tsx
+++ b/packages/design-system/src/components/select.tsx
@@ -157,7 +157,7 @@ const SelectBase = <Option,>(
</SelectButton>
</Primitive.Trigger>
<Primitive.Portal>
- <SelectContent>
+ <SelectContent css={{ zIndex: props.css?.zIndex ?? 0 }}>
<SelectScrollUpButton>
<ChevronUpIcon />
</SelectScrollUpButton>
diff --git a/packages/feature-flags/src/flags.ts b/packages/feature-flags/src/flags.ts
index 855c4b69b5..ea5c5e0ad9 100644
--- a/packages/feature-flags/src/flags.ts
+++ b/packages/feature-flags/src/flags.ts
@@ -2,4 +2,3 @@ export const example = false;
export const dark = false;
export const unsupportedBrowsers = false;
export const displayContents = false;
-export const breakpointsEditor = false;
diff --git a/packages/icons/icons/minus.svg b/packages/icons/icons/minus.svg
new file mode 100644
index 0000000000..311e680f92
--- /dev/null
+++ b/packages/icons/icons/minus.svg
@@ -0,0 +1,3 @@
+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M14 8C14 8.41421 13.6642 8.75 13.25 8.75H2.75C2.33579 8.75 2 8.41421 2 8C2 7.58579 2.33579 7.25 2.75 7.25H13.25C13.6642 7.25 14 7.58579 14 8Z" />
+</svg>
diff --git a/packages/icons/src/__generated__/index.ts b/packages/icons/src/__generated__/index.ts
index 7273dfe778..a87941dabc 100644
--- a/packages/icons/src/__generated__/index.ts
+++ b/packages/icons/src/__generated__/index.ts
@@ -85,6 +85,7 @@ export * from "./link";
export * from "./list-item";
export * from "./list";
export * from "./menu-ellipses";
+export * from "./minus";
export * from "./no-wrap";
export * from "./offline";
export * from "./order-first";
diff --git a/packages/icons/src/__generated__/minus.tsx b/packages/icons/src/__generated__/minus.tsx
new file mode 100644
index 0000000000..6f4b12d7df
--- /dev/null
+++ b/packages/icons/src/__generated__/minus.tsx
@@ -0,0 +1,15 @@
+// Generated from icons/minus.svg
+
+import { forwardRef } from "react";
+import type { IconProps } from "../types";
+
+// prettier-ignore
+export const MinusIcon = forwardRef<SVGSVGElement, IconProps>(
+ ({ color = "currentColor", size = 16, ...props }, forwardedRef) => {
+ return (
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width={size} height={size} fill={color} {...props} ref={forwardedRef}><path d="M14 8a.75.75 0 0 1-.75.75H2.75a.75.75 0 0 1 0-1.5h10.5A.75.75 0 0 1 14 8Z" clipRule="evenodd" /></svg>
+ );
+ }
+);
+
+MinusIcon.displayName = "MinusIcon";
diff --git a/packages/project-build/src/schema/breakpoints.ts b/packages/project-build/src/schema/breakpoints.ts
index 314c130f22..a6d32c6514 100644
--- a/packages/project-build/src/schema/breakpoints.ts
+++ b/packages/project-build/src/schema/breakpoints.ts
@@ -2,12 +2,22 @@ import { z } from "zod";
const BreakpointId = z.string();
-export const Breakpoint = z.object({
- id: BreakpointId,
- label: z.string(),
- minWidth: z.number().optional(),
- maxWidth: z.number().optional(),
-});
+export const Breakpoint = z
+ .object({
+ id: BreakpointId,
+ label: z.string(),
+ minWidth: z.number().optional(),
+ maxWidth: z.number().optional(),
+ })
+ .refine(({ minWidth, maxWidth }) => {
+ return (
+ // Either min or max width have to be defined
+ (minWidth !== undefined && maxWidth === undefined) ||
+ (minWidth === undefined && maxWidth !== undefined) ||
+ // This is a base breakpoint
+ (minWidth === undefined && maxWidth === undefined)
+ );
+ }, "Either minWidth or maxWidth should be defined");
export type Breakpoint = z.infer<typeof Breakpoint>;