Skip to content

Commit

Permalink
feat(components): add Color prop type to Plasmic components
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 852dfec134b436d7ea6cf0df8b4672c910afb743
  • Loading branch information
IcaroG authored and actions-user committed Feb 14, 2025
1 parent 30f8daf commit 386ee3e
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 21 deletions.
2 changes: 1 addition & 1 deletion platform/wab/cypress/e2e/hostless-rich-layout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe("hostless-rich-components", () => {
justType("#E6EEF4{enter}");
maybeSelectedElt()
.find(".ant-layout-header")
.should("have.css", "background-color", "rgba(230, 238, 244, 0)");
.should("have.css", "background-color", "rgb(230, 238, 244)");
checkDarkFgColors();
cy.get("[data-test-id='back-sidebar-modal']").click();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import { PropValueEditor } from "@/wab/client/components/sidebar-tabs/PropValueEditor";
import { SidebarModal } from "@/wab/client/components/sidebar/SidebarModal";
import { IconLinkButton } from "@/wab/client/components/widgets";
import {
IconLinkButton,
IFrameAwareDropdownMenu,
} from "@/wab/client/components/widgets";
import { Icon } from "@/wab/client/components/widgets/Icon";
import { IconButton } from "@/wab/client/components/widgets/IconButton";
import LabeledListItem from "@/wab/client/components/widgets/LabeledListItem";
import { Modal } from "@/wab/client/components/widgets/Modal";
import Select from "@/wab/client/components/widgets/Select";
import Textbox from "@/wab/client/components/widgets/Textbox";
import DotsVerticalIcon from "@/wab/client/plasmic/plasmic_kit/PlasmicIcon__DotsVertical";
import PlusIcon from "@/wab/client/plasmic/plasmic_kit/PlasmicIcon__Plus";
import PlasmicParamSection from "@/wab/client/plasmic/plasmic_kit_state_management/PlasmicParamSection";
import { StudioCtx } from "@/wab/client/studio-ctx/StudioCtx";
import { assert, ensure, mkShortId, spawn } from "@/wab/shared/common";
import { canRenameParam } from "@/wab/shared/core/components";
import { clone, codeLit, tryExtractJson } from "@/wab/shared/core/exprs";
import { mkParam } from "@/wab/shared/core/lang";
import {
getPropTypeType,
wabTypeToPropType,
} from "@/wab/shared/code-components/code-components";
import { assert, ensure, mkShortId, spawn } from "@/wab/shared/common";
import { canRenameParam } from "@/wab/shared/core/components";
import { clone, codeLit, tryExtractJson } from "@/wab/shared/core/exprs";
import { mkParam } from "@/wab/shared/core/lang";
import { cloneType } from "@/wab/shared/core/tpls";
import { COMPONENT_PROP_CAP } from "@/wab/shared/Labels";
import {
Component,
Expand All @@ -30,10 +37,9 @@ import {
} from "@/wab/shared/model/classes";
import { typeDisplayName, typeFactory } from "@/wab/shared/model/model-util";
import { smartHumanize } from "@/wab/shared/strs";
import { cloneType } from "@/wab/shared/core/tpls";
import { Menu } from "antd";
import { isNaN } from "lodash";
import React from "react";
import { Modal } from "@/wab/client/components/widgets/Modal";

function getComponentParamTypeOptions() {
return [
Expand All @@ -47,6 +53,7 @@ function getComponentParamTypeOptions() {
{ value: "href", label: "Link URL", isPrimitive: false },
{ value: "dateString", label: "Date", isPrimitive: true },
{ value: "dateRangeStrings", label: "Date Range", isPrimitive: true },
{ value: "color", label: "Color", isPrimitive: false },
] as const;
}

Expand Down Expand Up @@ -280,6 +287,23 @@ export function ComponentPropModal(props: {
)}
attr="default-value"
/>
<IFrameAwareDropdownMenu
menu={
<Menu>
<Menu.Item
onClick={() => {
setDefaultExpr(undefined);
}}
>
Unset
</Menu.Item>
</Menu>
}
>
<IconButton>
<DotsVerticalIcon />
</IconButton>
</IFrameAwareDropdownMenu>
</div>
),
}}
Expand Down Expand Up @@ -311,6 +335,23 @@ export function ComponentPropModal(props: {
)}
attr="preview-value"
/>
<IFrameAwareDropdownMenu
menu={
<Menu>
<Menu.Item
onClick={() => {
setDefaultExpr(undefined);
}}
>
Unset
</Menu.Item>
</Menu>
}
>
<IconButton>
<DotsVerticalIcon />
</IconButton>
</IFrameAwareDropdownMenu>
</div>
),
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ const PropValueEditor_ = (
)
: (value as string) || ""
}
valueSetState={valueSetState}
hideTokenPicker={hackyCast(propType).disableTokens}
sc={studioCtx}
data-plasmic-prop={attr}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { ColorPicker } from "@/wab/client/components/widgets/ColorPicker";
import { useClientTokenResolver } from "@/wab/client/components/widgets/ColorPicker/client-token-resolver";
import PlasmicColorButton from "@/wab/client/plasmic/plasmic_kit_style_controls/PlasmicColorButton";
import { StudioCtx } from "@/wab/client/studio-ctx/StudioCtx";
import { zeroWidthSpace } from "@/wab/shared/common";
import { isTokenRef, tryParseTokenRef } from "@/wab/commons/StyleToken";
import { TOKEN_CAP } from "@/wab/shared/Labels";
import { VariantedStylesHelper } from "@/wab/shared/VariantedStylesHelper";
import { zeroWidthSpace } from "@/wab/shared/common";
import { allColorTokens } from "@/wab/shared/core/sites";
import { StyleToken } from "@/wab/shared/model/classes";
import Chroma from "@/wab/shared/utils/color-utils";
import { allColorTokens } from "@/wab/shared/core/sites";
import { Tooltip } from "antd";
import { observer } from "mobx-react";
import * as React from "react";
Expand Down Expand Up @@ -77,6 +77,7 @@ function _ColorButton(props: ColorButtonProps) {
root: {
props: {
// ref,
type: "button",
"data-plasmic-prop": props["data-plasmic-prop"],
onClick: (e) => {
if (isDisabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ function ColorPicker_({
return null;
}

const realColor = ensure(maybeRealColor, "Unexpected empty real color");
const realColor =
color === ""
? "#FFFFFF"
: ensure(maybeRealColor, "Unexpected empty real color");
const colorPickerRef = useRef<HTMLDivElement>(null);
const [pickr, setPickr] = useState<Pickr | null>(null);
const [mode, setMode] = useState(ColorMode.hex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3913,10 +3913,7 @@ export function propTypeToWabType(
)
);
case "color":
// temporarily cast to any until type exists on host package
return success(
typeFactory.color({ noDeref: !!(type as any).keepCssVar })
);
return success(typeFactory.color({ noDeref: !!type.keepCssVar }));
case "object":
case "custom":
case "dataSource":
Expand Down
21 changes: 15 additions & 6 deletions platform/wab/src/wab/shared/model/model-util.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { assert, ensureInstance, objsEq, switchType } from "@/wab/shared/common";
import { Values } from "@/wab/commons/types";
import { getComponentDisplayName } from "@/wab/shared/core/components";
import { StudioPropType } from "@/wab/shared/code-components/code-components";
import { jsLiteral } from "@/wab/shared/codegen/util";
import {
assert,
ensureInstance,
objsEq,
switchType,
} from "@/wab/shared/common";
import { getComponentDisplayName } from "@/wab/shared/core/components";
import { StateVariableType } from "@/wab/shared/core/states";
import {
isTplComponent,
isTplFromComponent,
isTplTextBlock,
} from "@/wab/shared/core/tpls";
import {
AnyType,
ArgType,
Expand Down Expand Up @@ -49,8 +60,6 @@ import {
} from "@/wab/shared/model/classes";
import { instUtil as defaultInstUtil } from "@/wab/shared/model/InstUtil";
import { Type as ModelType } from "@/wab/shared/model/model-meta";
import { StateVariableType } from "@/wab/shared/core/states";
import { isTplComponent, isTplFromComponent, isTplTextBlock } from "@/wab/shared/core/tpls";
import L, {
isArray,
isBoolean,
Expand Down Expand Up @@ -130,8 +139,8 @@ export const typeFactory = {
includeTagStyles,
}),
defaultStyles: () => new DefaultStylesPropType({ name: "defaultStyles" }),
color: (opts: { noDeref: boolean }) =>
new ColorPropType({ name: "color", noDeref: opts.noDeref }),
color: (opts?: { noDeref: boolean }) =>
new ColorPropType({ name: "color", noDeref: opts ? !!opts.noDeref : true }),
};

export const genericTypes = [
Expand Down

0 comments on commit 386ee3e

Please sign in to comment.