-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for
backdrop-filter
property in style panel (#3317)
## Description This PR adds support for using `backdrop-filter` property in the style-panel. Here are more details on the property to test it around. https://developer.mozilla.org/en-US/docs/Web/CSS/backdrop-filter ## Steps for reproduction 1. Add an element to the canvas. 2. Click on the "+" icon in the style panel next to the `Backdrop Filters` section. 3. Edit the default filter that is added. 4. Swap the layers and publish the project. ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [x] made a self-review - [x] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [x] tested locally and on preview environment (preview dev login: 5de6)
- Loading branch information
1 parent
c196150
commit f529723
Showing
7 changed files
with
154 additions
and
23 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
apps/builder/app/builder/features/style-panel/sections/backdrop-filter/backdrop-filter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters