Skip to content

Commit

Permalink
feat: Add support for text-shadow property in style-panel (#3318)
Browse files Browse the repository at this point in the history
## 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
JayaKrishnaNamburu authored May 8, 2024
1 parent 0571d2d commit ce1f902
Show file tree
Hide file tree
Showing 11 changed files with 286 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,19 @@ export const Section = (props: SectionProps) => {
label={label}
tooltip={
<Tooltip
css={{ width: "208px" }}
variant="wrapped"
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
the area behind an element, for example:
<br />
<br />
<Text variant="monoBold">
{INITIAL_BACKDROP_FILTER}
</Text>
</Text>
</Flex>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import {
SectionTitle,
SectionTitleButton,
SectionTitleLabel,
Tooltip,
Text,
} from "@webstudio-is/design-system";
import { PlusIcon } from "@webstudio-is/icons";
import { InfoCircleIcon, PlusIcon } from "@webstudio-is/icons";
import type {
LayersValue,
StyleProperty,
Expand All @@ -16,9 +18,9 @@ import { PropertyName } from "../../shared/property-name";
import { getStyleSource } from "../../shared/style-info";
import type { SectionProps } from "../shared/section";
import { LayersList } from "../../style-layers-list";
import { BoxShadowLayer } from "./box-shadow-layer";
import { addLayer } from "../../style-layer-utils";
import { parseShadow } from "@webstudio-is/css-data";
import { ShadowLayer } from "../../shared/shadow-layer";

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

Expand Down Expand Up @@ -60,7 +62,7 @@ export const Section = (props: SectionProps) => {
}
>
<PropertyName
title="Box Shadows"
title={label}
style={currentStyle}
properties={properties}
description="Adds shadow effects around an element's frame."
Expand All @@ -79,9 +81,31 @@ export const Section = (props: SectionProps) => {
property={property}
layers={value}
{...props}
renderLayer={(layersProps) => (
<BoxShadowLayer key={layersProps.index} {...layersProps} />
)}
renderLayer={(layersProps) => {
return (
<ShadowLayer
key={layersProps.index}
{...layersProps}
label={label}
tooltip={
<Tooltip
variant="wrapped"
content={
<Text>
Paste a box-shadow CSS code without the property name,
for example:
<br />
<br />
<Text variant="monoBold">{INITIAL_BOX_SHADOW}</Text>
</Text>
}
>
<InfoCircleIcon />
</Tooltip>
}
/>
);
}}
/>
)}
</CollapsibleSectionRoot>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
InvalidValue,
LayersValue,
StyleProperty,
TupleValue,
} from "@webstudio-is/css-engine";
import {
Expand All @@ -18,6 +19,7 @@ import type { DeleteProperty } from "../../shared/use-style-data";
type FilterContentProps = {
index: number;
filter: string;
property: StyleProperty;
onEditLayer: (index: number, layers: LayersValue | TupleValue) => void;
deleteProperty: DeleteProperty;
tooltip: JSX.Element;
Expand All @@ -26,6 +28,7 @@ type FilterContentProps = {
export const FilterSectionContent = ({
index,
filter,
property,
onEditLayer,
deleteProperty,
tooltip,
Expand Down Expand Up @@ -101,7 +104,7 @@ export const FilterSectionContent = ({
return;
}

deleteProperty("filter", { isEphemeral: true });
deleteProperty(property, { isEphemeral: true });
setIntermediateValue(undefined);
event.preventDefault();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const FilterLayer = <T extends FunctionValue>(props: LayerProps<T>) => {
title={label}
content={
<FilterSectionContent
property={props.property}
index={index}
filter={filter}
onEditLayer={props.onEditLayer}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,17 @@ export const Section = (props: SectionProps) => {
label={label}
tooltip={
<Tooltip
css={{ width: "208px" }}
variant="wrapped"
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
element, for example:
<br />
<br />
<Text variant="monoBold">{INITIAL_FILTER}</Text>
</Text>
</Flex>
}
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 textShadows from "./text-shadows/text-shadows";
import * as backdropFilter from "./backdrop-filter/backdrop-filter";
import type { StyleProperty } from "@webstudio-is/css-engine";
import type { SectionProps } from "./shared/section";
Expand All @@ -31,6 +32,7 @@ export const sections = new Map<
["size", size],
["position", position],
["typography", typography],
["textShadows", textShadows],
["backgrounds", backgrounds],
["borders", borders],
["boxShadows", boxShadows],
Expand Down
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>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,16 @@ export const TransitionContent = ({

<Flex align="center">
<Tooltip
variant="wrapped"
content={
<Flex gap="2" direction="column">
<Text variant="regularBold">Duration</Text>
<Text variant="monoBold" color="moreSubtle">
transition-duration
</Text>
<Text>
Sets the length of time a
<br />
transition animation should take
<br /> to complete.
Sets the length of time a transition animation should take to
complete.
</Text>
</Flex>
}
Expand Down Expand Up @@ -161,16 +160,15 @@ export const TransitionContent = ({

<Flex align="center">
<Tooltip
variant="wrapped"
content={
<Flex gap="2" direction="column">
<Text variant="regularBold">Delay</Text>
<Text variant="monoBold" color="moreSubtle">
transition-delay
</Text>
<Text>
Specify the duration to wait
<br />
before the transition begins.
Specify the duration to wait before the transition begins.
</Text>
</Flex>
}
Expand Down Expand Up @@ -218,14 +216,11 @@ export const TransitionContent = ({
variant="wrapped"
content={
<Text>
Paste CSS code for a transition
<br />
or part of a transition, for
<br />
Paste CSS code for a transition or part of a transition, for
example:
<br />
<br />
opacity 200ms ease;
<Text variant="monoBold">opacity 200ms ease</Text>
</Text>
}
>
Expand Down
Loading

0 comments on commit ce1f902

Please sign in to comment.