Skip to content

Commit

Permalink
Merge branch 'main' into xml-gen.staging
Browse files Browse the repository at this point in the history
  • Loading branch information
kof authored May 8, 2024
2 parents 20533dd + f529723 commit ba17ed2
Show file tree
Hide file tree
Showing 18 changed files with 213 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const fieldDefaultValues = {
isHomePage: false,
title: `"Untitled"`,
description: `""`,
excludePageFromSearch: `false`,
excludePageFromSearch: `true`,
language: `""`,
socialImageUrl: `""`,
socialImageAssetId: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,12 @@ export const Section = ({
styleSource={getStyleSource(currentStyle[property])}
keywords={keywords}
value={currentStyle[property]?.value}
setValue={(styleValue, options) => {
setValue={(styleValue, options) =>
setProperty(property)(styleValue, {
...options,
listed: true,
});
}}
})
}
deleteProperty={deleteProperty}
/>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { CollapsibleSectionRoot } from "~/builder/shared/collapsible-section";
import type { SectionProps } from "../shared/section";
import type {
FunctionValue,
StyleProperty,
TupleValue,
} from "@webstudio-is/css-engine";
import { useState } from "react";
import {
SectionTitle,
SectionTitleButton,
SectionTitleLabel,
Tooltip,
Flex,
Text,
} from "@webstudio-is/design-system";
import { PropertyName } from "../../shared/property-name";
import { getStyleSource } from "../../shared/style-info";
import { getDots } from "../../shared/collapsible-section";
import { InfoCircleIcon, PlusIcon } from "@webstudio-is/icons";
import { addLayer } from "../../style-layer-utils";
import { parseFilter } from "@webstudio-is/css-data";
import { LayersList } from "../../style-layers-list";
import { FilterLayer } from "../filter/filter-layer";

export const properties = ["backdropFilter"] satisfies Array<StyleProperty>;

const property: StyleProperty = properties[0];
const label = "Backdrop Filters";
const INITIAL_BACKDROP_FILTER = "blur(0px)";

export const Section = (props: SectionProps) => {
const { currentStyle, deleteProperty } = props;
const [isOpen, setIsOpen] = useState(false);
const value = currentStyle[property]?.value;
const sectionStyleSource =
value?.type === "unparsed" || value?.type === "guaranteedInvalid"
? undefined
: getStyleSource(currentStyle[property]);

return (
<CollapsibleSectionRoot
fullWidth
label={label}
isOpen={isOpen}
onOpenChange={setIsOpen}
trigger={
<SectionTitle
dots={getDots(currentStyle, properties)}
suffix={
<Tooltip content={"Add a backdrop-filter"}>
<SectionTitleButton
prefix={<PlusIcon />}
onClick={() => {
addLayer(
property,
parseFilter(INITIAL_BACKDROP_FILTER),
currentStyle,
props.createBatchUpdate
);
setIsOpen(true);
}}
/>
</Tooltip>
}
>
<PropertyName
title={label}
style={currentStyle}
properties={properties}
description="Backdrop filters are similar to filters, but are applied to the area behind an element. This can be useful for creating frosted glass effects."
label={
<SectionTitleLabel color={sectionStyleSource}>
{label}
</SectionTitleLabel>
}
onReset={() => deleteProperty(property)}
/>
</SectionTitle>
}
>
{value?.type === "tuple" && value.value.length > 0 && (
<LayersList<FunctionValue, TupleValue>
{...props}
property={property}
layers={value}
renderLayer={(layerProps) => (
<FilterLayer
{...layerProps}
key={layerProps.index}
label={label}
tooltip={
<Tooltip
css={{ width: "208px" }}
content={
<Flex gap="2" direction="column">
<Text variant="regularBold">{label}</Text>
<Text variant="monoBold">backdrop-filter</Text>
<Text>
Applies graphical effects like blur or color shift to
the area behind an element
</Text>
</Flex>
}
>
<InfoCircleIcon />
</Tooltip>
}
/>
)}
/>
)}
</CollapsibleSectionRoot>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ const INITIAL_BOX_SHADOW = "0px 2px 5px 0px rgba(0, 0, 0, 0.2)";
export const Section = (props: SectionProps) => {
const { currentStyle, deleteProperty } = props;
const [isOpen, setIsOpen] = useState(true);
const layersStyleSource = getStyleSource(currentStyle[property]);
const value = currentStyle[property]?.value;
const sectionStyleSource =
value?.type === "unparsed" || value?.type === "guaranteedInvalid"
? undefined
: getStyleSource(currentStyle[property]);

return (
<CollapsibleSectionRoot
Expand Down Expand Up @@ -62,7 +65,7 @@ export const Section = (props: SectionProps) => {
properties={properties}
description="Adds shadow effects around an element's frame."
label={
<SectionTitleLabel color={layersStyleSource}>
<SectionTitleLabel color={sectionStyleSource}>
{label}
</SectionTitleLabel>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ import {
Flex,
theme,
Label,
Tooltip,
Text,
TextArea,
textVariants,
} from "@webstudio-is/design-system";
import { InfoCircleIcon } from "@webstudio-is/icons";
import { useState } from "react";
import type { IntermediateStyleValue } from "../../shared/css-value-input";
import { parseFilter } from "@webstudio-is/css-data";
Expand All @@ -23,13 +20,15 @@ type FilterContentProps = {
filter: string;
onEditLayer: (index: number, layers: LayersValue | TupleValue) => void;
deleteProperty: DeleteProperty;
tooltip: JSX.Element;
};

export const FilterSectionContent = ({
index,
filter,
onEditLayer,
deleteProperty,
tooltip,
}: FilterContentProps) => {
const [intermediateValue, setIntermediateValue] = useState<
IntermediateStyleValue | InvalidValue | undefined
Expand Down Expand Up @@ -73,21 +72,7 @@ export const FilterSectionContent = ({
<Label>
<Flex align={"center"} gap={1}>
Code
<Tooltip
content={
<Flex gap="2" direction="column">
<Text variant="regularBold">Filters</Text>
<Text variant="monoBold">filter</Text>
<Text>
Applies graphical effects like
<br />
blur or color shift to an element
</Text>
</Flex>
}
>
<InfoCircleIcon />
</Tooltip>
{tooltip}
</Flex>
</Label>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ import { useMemo } from "react";
import { FunctionValue, toValue } from "@webstudio-is/css-engine";

export const FilterLayer = <T extends FunctionValue>(props: LayerProps<T>) => {
const { index, id, layer, isHighlighted, onDeleteLayer } = props;
const { index, id, layer, isHighlighted, onDeleteLayer, label } = props;
const filter = useMemo(() => toValue(layer), [layer]);

return (
<FloatingPanel
title="Filter"
title={label}
content={
<FilterSectionContent
index={index}
filter={filter}
onEditLayer={props.onEditLayer}
deleteProperty={props.deleteProperty}
tooltip={props.tooltip}
/>
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ import { CollapsibleSectionRoot } from "~/builder/shared/collapsible-section";
import type { SectionProps } from "../shared/section";
import { useState } from "react";
import {
Flex,
SectionTitle,
SectionTitleButton,
SectionTitleLabel,
Tooltip,
Text,
} from "@webstudio-is/design-system";
import { getDots } from "../../shared/collapsible-section";
import { PropertyName } from "../../shared/property-name";
import { PlusIcon } from "@webstudio-is/icons";
import { InfoCircleIcon, PlusIcon } from "@webstudio-is/icons";
import {
FunctionValue,
TupleValue,
Expand All @@ -30,8 +32,11 @@ const INITIAL_FILTER = "blur(0px)";
export const Section = (props: SectionProps) => {
const { currentStyle, deleteProperty } = props;
const [isOpen, setIsOpen] = useState(true);
const layerStyleSource = getStyleSource(currentStyle[property]);
const value = currentStyle[property]?.value;
const sectionStyleSource =
value?.type === "unparsed" || value?.type === "guaranteedInvalid"
? undefined
: getStyleSource(currentStyle[property]);

return (
<CollapsibleSectionRoot
Expand All @@ -41,7 +46,7 @@ export const Section = (props: SectionProps) => {
onOpenChange={setIsOpen}
trigger={
<SectionTitle
dots={getDots(currentStyle, [property])}
dots={getDots(currentStyle, properties)}
suffix={
<Tooltip content={"Add a filter"}>
<SectionTitleButton
Expand All @@ -65,7 +70,7 @@ export const Section = (props: SectionProps) => {
properties={properties}
description="Filter effects allow you to apply graphical effects like blurring, color shifting, and more to elements."
label={
<SectionTitleLabel color={layerStyleSource}>
<SectionTitleLabel color={sectionStyleSource}>
{label}
</SectionTitleLabel>
}
Expand All @@ -80,7 +85,28 @@ export const Section = (props: SectionProps) => {
property={property}
layers={value}
renderLayer={(layerProps) => (
<FilterLayer {...layerProps} key={layerProps.index} />
<FilterLayer
{...layerProps}
key={layerProps.index}
label={label}
tooltip={
<Tooltip
css={{ width: "208px" }}
content={
<Flex gap="2" direction="column">
<Text variant="regularBold">{label}</Text>
<Text variant="monoBold">filter</Text>
<Text>
Applies graphical effects like blur or color shift to an
element
</Text>
</Flex>
}
>
<InfoCircleIcon />
</Tooltip>
}
/>
)}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as filter from "./filter/filter";
import * as transitions from "./transitions/transitions";
import * as outline from "./outline/outline";
import * as advanced from "./advanced/advanced";
import * as backdropFilter from "./backdrop-filter/backdrop-filter";
import type { StyleProperty } from "@webstudio-is/css-engine";
import type { SectionProps } from "./shared/section";

Expand All @@ -34,6 +35,7 @@ export const sections = new Map<
["borders", borders],
["boxShadows", boxShadows],
["filter", filter],
["backdropFilters", backdropFilter],
["transitions", transitions],
["outline", outline],
["advanced", advanced],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ const INITIAL_TRANSITION = "opacity 200ms ease";
export const Section = (props: SectionProps) => {
const { currentStyle, deleteProperty } = props;
const [isOpen, setIsOpen] = useState(true);
const layersStyleSource = getStyleSource(currentStyle[property]);
const value = currentStyle[property]?.value;
const sectionStyleSource =
value?.type === "unparsed" || value?.type === "guaranteedInvalid"
? undefined
: getStyleSource(currentStyle[property]);

const selectedOrLastStyleSourceSelector = useStore(
$selectedOrLastStyleSourceSelector
Expand Down Expand Up @@ -82,7 +85,7 @@ export const Section = (props: SectionProps) => {
description="Animate the transition between states on this instance."
properties={properties}
label={
<SectionTitleLabel color={layersStyleSource}>
<SectionTitleLabel color={sectionStyleSource}>
{label}
</SectionTitleLabel>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@ export const getDots = (
const dots = new Set<"local" | "overwritten" | "remote">();

for (const property of properties) {
const source = getStyleSource(currentStyle[property]);
const style = currentStyle[property];

// Unparsed values are not editable directly in the section, so we don't show the dot
if (
style?.value.type === "unparsed" ||
style?.value.type === "guaranteedInvalid"
) {
return;
}

const source = getStyleSource(style);
if (source === "local" || source === "overwritten" || source === "remote") {
dots.add(source);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ export const addLayer = <T extends LayersValue | TupleValue>(
value.value = [...value.value, ...existingValues.value] as T["value"];
}

if (property === "filter" && existingValues?.type === "tuple") {
if (
(property === "filter" || property === "backdropFilter") &&
existingValues?.type === "tuple"
) {
value.value = [
...value.value,
...(existingValues?.value || []),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export type LayerProps<LayerType> = {
id: string;
index: number;
layer: LayerType;
label: string;
tooltip: JSX.Element;
isHighlighted: boolean;
disabled?: boolean;
onLayerHide: (index: number) => void;
Expand Down
Loading

0 comments on commit ba17ed2

Please sign in to comment.