-
Notifications
You must be signed in to change notification settings - Fork 798
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
text-shadow
property in style-panel (#3318)
## 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/text-shadow ## Steps for reproduction 1. Add an element to the canvas. 2. Click on the "+" icon in the style panel next to the `Text Shadows` 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
0571d2d
commit ce1f902
Showing
11 changed files
with
286 additions
and
151 deletions.
There are no files selected for viewing
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
111 changes: 111 additions & 0 deletions
111
apps/builder/app/builder/features/style-panel/sections/text-shadows/text-shadows.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,111 @@ | ||
import { CollapsibleSectionRoot } from "~/builder/shared/collapsible-section"; | ||
import type { SectionProps } from "../shared/section"; | ||
import type { | ||
LayersValue, | ||
StyleProperty, | ||
TupleValue, | ||
} from "@webstudio-is/css-engine"; | ||
import { useState } from "react"; | ||
import { | ||
SectionTitle, | ||
SectionTitleButton, | ||
SectionTitleLabel, | ||
Tooltip, | ||
Text, | ||
} from "@webstudio-is/design-system"; | ||
import { InfoCircleIcon, PlusIcon } from "@webstudio-is/icons"; | ||
import { addLayer } from "../../style-layer-utils"; | ||
import { parseShadow } from "@webstudio-is/css-data"; | ||
import { getDots } from "../../shared/collapsible-section"; | ||
import { PropertyName } from "../../shared/property-name"; | ||
import { getStyleSource } from "../../shared/style-info"; | ||
import { LayersList } from "../../style-layers-list"; | ||
import { ShadowLayer } from "../../shared/shadow-layer"; | ||
|
||
export const properties = ["textShadow"] satisfies Array<StyleProperty>; | ||
|
||
const property: StyleProperty = properties[0]; | ||
const label = "Text Shadows"; | ||
const INITIAL_TEXT_SHADOW = "0px 2px 5px rgba(0, 0, 0, 0.2)"; | ||
|
||
export const Section = (props: SectionProps) => { | ||
const { currentStyle, createBatchUpdate, 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={ | ||
<SectionTitleButton | ||
prefix={<PlusIcon />} | ||
onClick={() => { | ||
addLayer( | ||
property, | ||
parseShadow("textShadow", INITIAL_TEXT_SHADOW), | ||
currentStyle, | ||
createBatchUpdate | ||
); | ||
setIsOpen(true); | ||
}} | ||
/> | ||
} | ||
> | ||
<PropertyName | ||
title={label} | ||
style={currentStyle} | ||
properties={properties} | ||
description="Adds shadow effects around a text." | ||
label={ | ||
<SectionTitleLabel color={sectionStyleSource}> | ||
{label} | ||
</SectionTitleLabel> | ||
} | ||
onReset={() => deleteProperty(property)} | ||
/> | ||
</SectionTitle> | ||
} | ||
> | ||
{value?.type === "layers" && value.value.length > 0 && ( | ||
<LayersList<TupleValue, LayersValue> | ||
property={property} | ||
layers={value} | ||
{...props} | ||
renderLayer={(layersProps) => ( | ||
<ShadowLayer | ||
{...layersProps} | ||
key={layersProps.index} | ||
label={label} | ||
tooltip={ | ||
<Tooltip | ||
variant="wrapped" | ||
content={ | ||
<Text> | ||
Paste a text-shadow CSS code without the property name, | ||
for example: | ||
<br /> | ||
<br /> | ||
<Text variant="monoBold">{INITIAL_TEXT_SHADOW}</Text> | ||
</Text> | ||
} | ||
> | ||
<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
Oops, something went wrong.