Skip to content

Commit 7278aa6

Browse files
committed
Add a placeholder property to input mock shape
1 parent ee22b03 commit 7278aa6

File tree

9 files changed

+87
-3
lines changed

9 files changed

+87
-3
lines changed

src/common/components/mock-components/front-components/input-shape.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,15 @@ export const InputShape = forwardRef<any, ShapeProps>((props, ref) => {
4141

4242
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;
4343

44-
const { stroke, fill, textColor, strokeStyle, borderRadius, disabled } =
45-
useShapeProps(otherProps, INPUT_SHAPE);
44+
const {
45+
stroke,
46+
fill,
47+
textColor,
48+
strokeStyle,
49+
borderRadius,
50+
disabled,
51+
isPlaceholder,
52+
} = useShapeProps(otherProps, INPUT_SHAPE);
4653

4754
const commonGroupProps = useGroupShapeProps(
4855
props,
@@ -72,7 +79,13 @@ export const InputShape = forwardRef<any, ShapeProps>((props, ref) => {
7279
fontFamily={INPUT_SHAPE.DEFAULT_FONT_FAMILY}
7380
fontSize={INPUT_SHAPE.DEFAULT_FONT_SIZE}
7481
lineHeight={INPUT_SHAPE.DEFAULT_LINE_HEIGHT}
75-
fill={disabled ? DISABLED_COLOR_VALUES.DEFAULT_TEXT_COLOR : textColor}
82+
fill={
83+
disabled
84+
? DISABLED_COLOR_VALUES.DEFAULT_TEXT_COLOR
85+
: isPlaceholder
86+
? INPUT_SHAPE.DEFAULT_FILL_TEXT
87+
: textColor
88+
}
7689
align="left"
7790
ellipsis={true}
7891
wrap="none"

src/common/components/shapes/use-shape-props.hook.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export const useShapeProps = (
2222
[otherProps?.textColor]
2323
);
2424

25+
const isPlaceholder = useMemo(
26+
() => otherProps?.isPlaceholder ?? true,
27+
[otherProps?.isPlaceholder]
28+
);
29+
2530
const fontVariant = useMemo(
2631
() => otherProps?.fontVariant ?? defaultStyleShape.DEFAULT_FONT_VARIANT,
2732
[otherProps?.fontVariant]
@@ -93,5 +98,6 @@ export const useShapeProps = (
9398
textDecoration,
9499
textAlignment,
95100
disabled,
101+
isPlaceholder,
96102
};
97103
};

src/core/model/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export interface OtherProps {
182182
selectedBackgroundColor?: string;
183183
textAlignment?: 'left' | 'center' | 'right';
184184
disabled?: boolean;
185+
isPlaceholder?: boolean;
185186
}
186187

187188
export const BASE_ICONS_URL = '/icons/';

src/pods/canvas/model/shape-other-props.utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const generateDefaultOtherProps = (
1515
stroke: INPUT_SHAPE.DEFAULT_STROKE_COLOR,
1616
backgroundColor: INPUT_SHAPE.DEFAULT_FILL_BACKGROUND,
1717
textColor: INPUT_SHAPE.DEFAULT_FILL_TEXT,
18+
isPlaceholder: true,
1819
strokeStyle: [],
1920
borderRadius: `${INPUT_SHAPE.DEFAULT_CORNER_RADIUS}`,
2021
disabled: INPUT_SHAPE.DEFAULT_DISABLED,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './placeholder.component';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.container {
2+
display: flex;
3+
gap: 0.5em;
4+
align-items: center;
5+
padding: var(--space-xs) var(--space-md);
6+
border-bottom: 1px solid var(--primary-300);
7+
}
8+
9+
.container :first-child {
10+
flex: 1;
11+
}
12+
13+
.checkbox {
14+
width: var(--space-md);
15+
height: var(--space-md);
16+
cursor: pointer;
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import classes from './placeholder.component.module.css';
2+
3+
interface Props {
4+
label: string;
5+
isPlaceholder: boolean;
6+
onChange: (isPlaceholder: boolean) => void;
7+
}
8+
9+
export const Placeholder: React.FC<Props> = props => {
10+
const { label, isPlaceholder, onChange } = props;
11+
12+
return (
13+
<div className={classes.container}>
14+
<p>{label}</p>
15+
<input
16+
type="checkbox"
17+
checked={isPlaceholder}
18+
onChange={() => onChange(!isPlaceholder)}
19+
className={classes.checkbox}
20+
/>
21+
</div>
22+
);
23+
};

src/pods/properties/properties.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const multiSelectEnabledProperties: (keyof OtherProps)[] = [
1919
'selectedBackgroundColor',
2020
'textAlignment',
2121
'disabled',
22+
'isPlaceholder',
2223
];
2324

2425
export type PropsValueTypes =

src/pods/properties/properties.pod.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { useMemo } from 'react';
1818
import { extractMultiplePropsInCommon } from './properties.business';
1919
import { ShowProp } from './components/show-prop';
2020
import { iconCollection } from './components/icon-selector/modal/icons';
21+
import { Placeholder } from './components/placeholder';
2122

2223
export const PropertiesPod = () => {
2324
const { selectionInfo, fullDocument } = useCanvasContext();
@@ -191,6 +192,26 @@ export const PropertiesPod = () => {
191192
}
192193
/>
193194
</ShowProp>
195+
<ShowProp
196+
singleSelection={isSingleSelection}
197+
multipleSelectionPropsInCommon={multipleSelectionPropsInCommon}
198+
propKey="isPlaceholder"
199+
propValue={selectedShapeData?.otherProps?.isPlaceholder}
200+
>
201+
<Placeholder
202+
label="Placeholder"
203+
isPlaceholder={
204+
selectedShapeData?.otherProps?.isPlaceholder ?? false
205+
}
206+
onChange={isPlaceholder =>
207+
updateOtherPropsOnSelected(
208+
'isPlaceholder',
209+
isPlaceholder,
210+
isMultipleSelection
211+
)
212+
}
213+
/>
214+
</ShowProp>
194215
<ShowProp
195216
singleSelection={isSingleSelection}
196217
multipleSelectionPropsInCommon={multipleSelectionPropsInCommon}

0 commit comments

Comments
 (0)