Skip to content

Commit

Permalink
Add proprety reset button in popover
Browse files Browse the repository at this point in the history
Ref #29
  • Loading branch information
TrySound committed Dec 10, 2022
1 parent b353cf1 commit 17da4ab
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 54 deletions.
6 changes: 6 additions & 0 deletions apps/designer/app/canvas/shared/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ export const useCssRules = ({
for (property in dynamicStyle) {
rule.styleMap.set(property, dynamicStyle[property]);
}
// delete previously rendered properties when reset
for (const property of rule.styleMap.keys()) {
if (dynamicStyle[property] == null) {
rule.styleMap.delete(property);
}
}
}
cssEngine.render();
}, [id, cssRules]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ const FlexChildSectionAlign = (props: RenderCategoryProps) => {
<PropertyName
property={sectionStyle.alignSelf?.styleConfig.property}
label="Align"
onReset={() => {
sectionStyle.alignSelf.setProperty(
sectionStyle.alignSelf?.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<ToggleGroupControl
property={sectionStyle.alignSelf?.styleConfig.property}
Expand Down Expand Up @@ -92,6 +97,11 @@ const FlexChildSectionSizing = (props: RenderCategoryProps) => {
sectionStyle.flexShrink?.styleConfig.property,
]}
label="Sizing"
onReset={() => {
setSizing.setProperty("flexGrow")({ type: "unset", value: "" });
setSizing.setProperty("flexShrink")({ type: "unset", value: "" });
setSizing.publish();
}}
/>
<ToggleGroupControl
property={[
Expand Down Expand Up @@ -169,20 +179,35 @@ const FlexChildSectionSizingPopover = ({
<PropertyName
property={sectionStyle.flexBasis?.styleConfig.property}
label="Basis"
onReset={() => {
sectionStyle.flexBasis.setProperty(
sectionStyle.flexBasis?.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<TextControl {...sectionStyle.flexBasis} />
</Grid>
<Grid css={{ gridTemplateColumns: "auto", gap: "$spacing$3" }}>
<PropertyName
property={sectionStyle.flexGrow?.styleConfig.property}
label="Grow"
onReset={() => {
sectionStyle.flexGrow.setProperty(
sectionStyle.flexGrow?.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<TextControl {...sectionStyle.flexGrow} />
</Grid>
<Grid css={{ gridTemplateColumns: "auto", gap: "$spacing$3" }}>
<PropertyName
property={sectionStyle.flexShrink?.styleConfig.property}
label="Shrink"
onReset={() => {
sectionStyle.flexShrink.setProperty(
sectionStyle.flexShrink?.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<TextControl {...sectionStyle.flexShrink} />
</Grid>
Expand All @@ -205,6 +230,11 @@ const FlexChildSectionOrder = (props: RenderCategoryProps) => {
<PropertyName
property={sectionStyle.order?.styleConfig.property}
label="Order"
onReset={() => {
sectionStyle.order.setProperty(
sectionStyle.order?.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<ToggleGroupControl
property={sectionStyle.order?.styleConfig.property}
Expand Down Expand Up @@ -257,6 +287,11 @@ const FlexChildSectionOrderPopover = (props: RenderCategoryProps) => {
<PropertyName
property={sectionStyle.order?.styleConfig.property}
label="Order"
onReset={() => {
sectionStyle.order.setProperty(
sectionStyle.order?.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<TextControl {...sectionStyle.order} />
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ const LayoutSectionFlex = ({
<PropertyName
property={display.styleConfig.property}
label={display.styleConfig.label}
onReset={() => {
sectionStyle.display.setProperty(
sectionStyle.display.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<SelectControl {...display} />
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,39 @@ export const TypographySectionFont = (props: RenderCategoryProps) => {
}}
>
<Grid css={{ gridTemplateColumns: "4fr 6fr" }}>
<PropertyName label="Font" property="fontFamily" />
<PropertyName
label="Font"
property="fontFamily"
onReset={() => {
sectionStyle.fontFamily.setProperty(
sectionStyle.fontFamily.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<FontFamilyControl {...sectionStyle.fontFamily} />
</Grid>
<Grid css={{ gridTemplateColumns: "4fr 6fr" }}>
<PropertyName label="Weight" property="fontWeight" />
<PropertyName
label="Weight"
property="fontWeight"
onReset={() => {
sectionStyle.fontWeight.setProperty(
sectionStyle.fontWeight.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<FontWeightControl {...sectionStyle.fontWeight} />
</Grid>
<Grid css={{ gridTemplateColumns: "4fr 6fr" }}>
<PropertyName label="Color" property="color" />
<PropertyName
label="Color"
property="color"
onReset={() => {
sectionStyle.color.setProperty(
sectionStyle.color.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<ColorControl {...sectionStyle.color} />
</Grid>
</Grid>
Expand All @@ -81,15 +105,39 @@ export const TypographySectionSizing = (props: RenderCategoryProps) => {
}}
>
<Grid css={{ gridTemplateColumns: "auto", gap: "$spacing$3" }}>
<PropertyName property="fontSize" label="Size" />
<PropertyName
property="fontSize"
label="Size"
onReset={() => {
sectionStyle.fontSize.setProperty(
sectionStyle.fontSize.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<TextControl {...sectionStyle.fontSize} />
</Grid>
<Grid css={{ gridTemplateColumns: "auto", gap: "$spacing$3" }}>
<PropertyName property="lineHeight" label="Height" />
<PropertyName
property="lineHeight"
label="Height"
onReset={() => {
sectionStyle.lineHeight.setProperty(
sectionStyle.lineHeight.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<TextControl {...sectionStyle.lineHeight} />
</Grid>
<Grid css={{ gridTemplateColumns: "auto", gap: "$spacing$3" }}>
<PropertyName property="letterSpacing" label="Spacing" />
<PropertyName
property="letterSpacing"
label="Spacing"
onReset={() => {
sectionStyle.letterSpacing.setProperty(
sectionStyle.letterSpacing.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<TextControl {...sectionStyle.letterSpacing} />
</Grid>
</Grid>
Expand Down Expand Up @@ -235,11 +283,27 @@ export const TypographySectionAdvancedPopover = (
content={
<Grid css={{ padding: "$spacing$9", gap: "$spacing$9" }}>
<Grid css={{ gridTemplateColumns: "4fr 6fr" }}>
<PropertyName property="whiteSpace" label="White Space" />
<PropertyName
property="whiteSpace"
label="White Space"
onReset={() => {
sectionStyle.whiteSpace.setProperty(
sectionStyle.whiteSpace.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<SelectControl {...sectionStyle.whiteSpace} />
</Grid>
<Grid css={{ gridTemplateColumns: "4fr auto" }}>
<PropertyName property="direction" label="Direction" />
<PropertyName
property="direction"
label="Direction"
onReset={() => {
sectionStyle.direction.setProperty(
sectionStyle.direction.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<ToggleGroupControl
property="direction"
onValueChange={(value) => setDirection(value)}
Expand All @@ -259,7 +323,15 @@ export const TypographySectionAdvancedPopover = (
/>
</Grid>
<Grid css={{ gridTemplateColumns: "4fr auto" }}>
<PropertyName property="hyphens" label="Hyphens" />
<PropertyName
property="hyphens"
label="Hyphens"
onReset={() => {
sectionStyle.hyphens.setProperty(
sectionStyle.hyphens.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<ToggleGroupControl
property="hyphens"
onValueChange={(value) => setHyphens(value)}
Expand All @@ -279,7 +351,15 @@ export const TypographySectionAdvancedPopover = (
/>
</Grid>
<Grid css={{ gridTemplateColumns: "4fr auto" }}>
<PropertyName property="textOverflow" label="Text Overflow" />
<PropertyName
property="textOverflow"
label="Text Overflow"
onReset={() => {
sectionStyle.textOverflow.setProperty(
sectionStyle.textOverflow.styleConfig.property
)({ type: "unset", value: "" });
}}
/>
<ToggleGroupControl
property="textOverflow"
onValueChange={(value) => setTextOverflow(value)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,89 @@
import { Flex, Label, Tooltip } from "@webstudio-is/design-system";
import { useState } from "react";
import type { StyleProperty } from "@webstudio-is/css-data";
import {
Button,
Flex,
Box,
Text,
Label,
Tooltip,
Popover,
PopoverContent,
PopoverPortal,
PopoverTrigger,
Separator,
} from "@webstudio-is/design-system";
import { UndoIcon } from "@webstudio-is/icons";
import { useIsFromCurrentBreakpoint } from "./use-is-from-current-breakpoint";
import { propertyNameColorForSelectedBreakpoint } from "./constants";
import type { PropertyProps } from "../style-sections";

export const PropertyName = ({ property, label, css }: PropertyProps) => {
type PropertyProps = {
property: StyleProperty | StyleProperty[];
label: string;
onReset: () => void;
};

export const PropertyName = ({ property, label, onReset }: PropertyProps) => {
const isCurrentBreakpoint = useIsFromCurrentBreakpoint(property);
const [isOpen, setIsOpen] = useState(false);
const isPopoverEnabled = isCurrentBreakpoint;

const labelElement = (
<Label
css={{
fontWeight: "inherit",
padding: "calc($spacing$3 / 2) $spacing$3",
...(isCurrentBreakpoint
? {
color: "$blue11",
backgroundColor: "$colors$blue4",
borderRadius: "$borderRadius$4",
}
: {
color: "$hiContrast",
}),
}}
htmlFor={property.toString()}
>
{label}
</Label>
);

if (isPopoverEnabled) {
return (
<Flex align="center">
<Popover modal open={isOpen} onOpenChange={setIsOpen}>
<PopoverTrigger asChild aria-label="Show proprety description">
{labelElement}
</PopoverTrigger>
<PopoverPortal>
<PopoverContent align="start" onClick={() => setIsOpen(false)}>
<Flex align="start" css={{ padding: "$spacing$3 $spacing$4" }}>
<Button onClick={onReset}>
<UndoIcon /> &nbsp; Reset
</Button>
</Flex>
<Separator />
<Box css={{ padding: "$spacing$3 $spacing$4" }}>
<Text color="hint">
Resetting will revert to initial or inherited value
</Text>
</Box>
</PopoverContent>
</PopoverPortal>
</Popover>
</Flex>
);
}

return (
<Tooltip content={label} delayDuration={600} disableHoverableContent={true}>
<Flex
css={{
...css,
alignItems: "center",
}}
<Flex align="center">
<Tooltip
content={label}
delayDuration={600}
disableHoverableContent={true}
>
<Label
css={{
gridColumn: "1",
fontWeight: "inherit",
...(isCurrentBreakpoint
? {
color: propertyNameColorForSelectedBreakpoint,
backgroundColor: "$colors$blue4",
padding: "calc($spacing$3 / 2) $spacing$3",
borderRadius: "$borderRadius$4",
}
: {
color: "$hiContrast",
}),
}}
htmlFor={String(property)}
>
{label}
</Label>
</Flex>
</Tooltip>
{labelElement}
</Tooltip>
</Flex>
);
};
PropertyName.displayName = "PropertyName";

0 comments on commit 17da4ab

Please sign in to comment.