Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
wip using background image control
Oleg Isonenb70132f4b0bb
diff --git a/apps/designer/app/designer/features/style-panel/controls/image/image-control.tsx b/apps/designer/app/designer/features/style-panel/controls/background-image/background-image-control.tsxsimilarity index 67%rename from apps/designer/app/designer/features/style-panel/controls/image/image-control.tsxrename to apps/designer/app/designer/features/style-panel/controls/background-image/background-image-control.tsxindex a1a0cb676e..46e7031767 100644--- a/apps/designer/app/designer/features/style-panel/controls/image/image-control.tsx+++ b/apps/designer/app/designer/features/style-panel/controls/background-image/background-image-control.tsx@@ -4,7 +4,9 @@ import { getFinalValue } from "../../shared/get-final-value";import { PropertyName } from "../../shared/property-name";import { ValuePickerPopover } from "../../shared/value-picker-popover";import { ImageManager } from "~/designer/shared/image-manager";+//import { useAssets } from "~/designer/shared/assets";+// @todo get rid of this custom styling, it should be part of the design system and/or reused across style panelconst textFieldStyle = {paddingLeft: "calc($sizes$1 + $nudge$3)",textAlign: "left",@@ -12,12 +14,13 @@ const textFieldStyle = {fontWeight: "500",};-export const ImageControl = ({+export const BackgroundImageControl = ({currentStyle,inheritedStyle,//setProperty,styleConfig,}: ControlProps) => {+ //const { assets } = useAssets("image");// @todo show which instance we inherited the value fromconst value = getFinalValue({currentStyle,@@ -29,16 +32,27 @@ export const ImageControl = ({//const setValue = setProperty(styleConfig.property);+ //const selectedAsset = assets.find((asset) => asset.id === value.value);+return (<Grid columns={2}><PropertyName property={styleConfig.property} label={styleConfig.label} />- <ValuePickerPopover title="Images" content={<ImageManager />}>+ <ValuePickerPopover+ title="Images"+ content={+ <ImageManager+ onSelect={() => {+ //setValue(asset.id);+ }}+ />+ }+ >{/* @todo this should be part of the design system, probably a varian="button" */}<TextFieldcss={textFieldStyle}spellCheck={false}readOnly- defaultValue={value.value}+ //defaultValue={selectedAsset?.name}/></ValuePickerPopover></Grid>diff --git a/apps/designer/app/designer/features/style-panel/controls/font-family/font-family-control.tsx b/apps/designer/app/designer/features/style-panel/controls/font-family/font-family-control.tsxindex 48d71ee211..c64ce4a5a0 100644--- a/apps/designer/app/designer/features/style-panel/controls/font-family/font-family-control.tsx+++ b/apps/designer/app/designer/features/style-panel/controls/font-family/font-family-control.tsx@@ -5,6 +5,7 @@ import { getFinalValue } from "../../shared/get-final-value";import { PropertyName } from "../../shared/property-name";import { ValuePickerPopover } from "../../shared/value-picker-popover";+// @todo get rid of this custom styling, it should be part of the design system and/or reused across style panelconst textFieldStyle = {paddingLeft: "calc($sizes$1 + $nudge$3)",textAlign: "left",diff --git a/apps/designer/app/designer/features/style-panel/style-sections.tsx b/apps/designer/app/designer/features/style-panel/style-sections.tsxindex 56200dbb4c..c9643bc000 100644--- a/apps/designer/app/designer/features/style-panel/style-sections.tsx+++ b/apps/designer/app/designer/features/style-panel/style-sections.tsx@@ -18,7 +18,7 @@ import {} from "./controls";import { ShowMore } from "./shared/show-more";import { LayoutSection } from "./sections";-import { ImageControl } from "./controls/image/image-control";+import { BackgroundImageControl } from "./controls/background-image/background-image-control";export type PropertyProps = {property: StyleProperty;@@ -138,5 +138,5 @@ const controls: {Select: SelectControl,Spacing: SpacingControl,FontFamily: FontFamilyControl,- Image: ImageControl,+ Image: BackgroundImageControl,};diff --git a/apps/designer/app/designer/shared/image-manager/image-manager.tsx b/apps/designer/app/designer/shared/image-manager/image-manager.tsxindex ac239f17d6..f46c15bec4 100644--- a/apps/designer/app/designer/shared/image-manager/image-manager.tsx+++ b/apps/designer/app/designer/shared/image-manager/image-manager.tsx@@ -1,9 +1,14 @@import { Box, Flex, Grid } from "@webstudio-is/design-system";+import type { Asset } from "@webstudio-is/asset-uploader";import { ImageThumbnail } from "./image-thumbnail";import { AssetUpload } from "../assets/asset-upload";import { useAssets } from "../assets/use-assets";-export const ImageManager = () => {+type ImageManagerProps = {+ onSelect?: (asset: Asset) => void;+};++export const ImageManager = ({ onSelect }: ImageManagerProps) => {const { assets, onSubmitAssets, onActionData, onDelete } = useAssets("image");return (<Flex gap="3" direction="column" css={{ padding: "$1", paddingTop: "$2" }}>@@ -16,7 +21,12 @@ export const ImageManager = () => {</Box><Grid columns={2} gap={2}>{assets.map((asset) => (- <ImageThumbnail key={asset.id} asset={asset} onDelete={onDelete} />+ <ImageThumbnail+ key={asset.id}+ asset={asset}+ onDelete={onDelete}+ onSelect={onSelect}+ />))}</Grid></Flex>diff --git a/apps/designer/app/designer/shared/image-manager/image-thumbnail.tsx b/apps/designer/app/designer/shared/image-manager/image-thumbnail.tsxindex b8e090b187..1cc5751627 100644--- a/apps/designer/app/designer/shared/image-manager/image-thumbnail.tsx+++ b/apps/designer/app/designer/shared/image-manager/image-thumbnail.tsx@@ -27,9 +27,10 @@ const useImageWithFallback = ({type ThumbnailProps = {path?: string;status: Asset["status"];+ onClick: () => void;};-export const Thumbnail = ({ path, status }: ThumbnailProps) => {+const Thumbnail = ({ path, status, onClick }: ThumbnailProps) => {const src = useImageWithFallback({ path });return (@@ -48,6 +49,7 @@ export const Thumbnail = ({ path, status }: ThumbnailProps) => {? { filter: "blur(1px)", opacity: 0.7 }: {}),}}+ onClick={onClick}></Box>);};@@ -55,9 +57,11 @@ export const Thumbnail = ({ path, status }: ThumbnailProps) => {export const ImageThumbnail = ({asset,onDelete,+ onSelect,}: {asset: Asset | PreviewAsset;onDelete: (ids: Array<string>) => void;+ onSelect?: (asset: Asset) => void;}) => {const { path, status, name } = asset;const description =@@ -79,7 +83,13 @@ export const ImageThumbnail = ({"&:hover": imageInfoTriggerCssVars({ show: true }),}}>- <Thumbnail path={path} status={status} />+ <Thumbnail+ path={path}+ status={status}+ onClick={() => {+ if (isUploadedAsset) onSelect?.(asset);+ }}+ />{isUploadedAsset && (<ImageInfoTriggerasset={asset}