Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mikk number input placeholder #1937

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ const numberInputStyle = css({
textAlign: 'center',
});

export type NumberInputProps = InputProps<number>;
interface NumberInputProps extends InputProps<number> {
placeholder?: string,
}

export function NumberInput(props: NumberInputProps) {
const { value } = props;
const { value, placeholder } = props;
const valueRef = React.useRef(String(value));
const [inputValue, setInputValue] = React.useState<string>('');

Expand All @@ -37,6 +39,7 @@ export function NumberInput(props: NumberInputProps) {
}
}}
inputType='number'
placeholder={placeholder}
onBlur={onBlur}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,23 @@ export interface NumberSliderProps
* handleStyle - the style of the slider handle
*/
handleStyle?: CSSInterpolation;
placeholder?: string,
}

const desinterpolate = (style?: CSSInterpolation) =>
style
? Object.keys(style).reduce(
(o, k: keyof CSSInterpolation) => ({
...o,
[k]: style[k],
}),
{},
)
(o, k: keyof CSSInterpolation) => ({
...o,
[k]: style[k],
}),
{},
)
: undefined;

export function NumberSlider({
value,
placeholder,
onChange,
max,
min,
Expand Down Expand Up @@ -156,6 +158,7 @@ export function NumberSlider({
}}
disabled={disabled}
readOnly={readOnly}
placeholder={placeholder}
/>
);
break;
Expand All @@ -168,16 +171,7 @@ export function NumberSlider({
display = displayValues(internalValue, value);
}
return <div className={valueDisplayStyle}>{display}</div>;
}, [
disabled,
displayValues,
internalValue,
max,
min,
onNumberChange,
readOnly,
value,
]);
}, [disabled, displayValues, internalValue, max, min, onNumberChange, placeholder, readOnly, value]);

const computedSteps = Math.abs(max - min) / (steps ?? 100);

Expand All @@ -192,13 +186,13 @@ export function NumberSlider({
active: leftPartStyle
? desinterpolate(leftPartStyle)
: desinterpolate({
backgroundColor: themeVar.colors.PrimaryColor,
}),
backgroundColor: themeVar.colors.PrimaryColor,
}),
thumb: handleStyle
? desinterpolate(handleStyle)
: isActionAllowed({ readOnly, disabled })
? desinterpolate({ cursor: 'pointer' })
: {},
? desinterpolate({ cursor: 'pointer' })
: {},
disabled: { opacity: 0.5 },
}}
axis="x"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ interface PlayerNumberInputProps extends WegasComponentProps {
* script - the script that returns the variable to display and modify
*/
script?: IScript;
/**
* placeholder - the grey text inside the box when nothing is written
*/
placeholder?: IScript;
onVariableChange?: OnVariableChange;
}

Expand All @@ -40,6 +44,7 @@ function PlayerNumberInput({
className,
style,
id,
placeholder,
onVariableChange,
options,
pageId,
Expand All @@ -49,6 +54,7 @@ function PlayerNumberInput({
const { readOnly, disabled, locked } = options;

const number = useScript<SNumberDescriptor | number>(script, context);
const placeholderText = useScript<string>(placeholder, context);

const value = useStore(() =>
typeof number === 'object' ? number.getValue(Player.self()) : number,
Expand Down Expand Up @@ -94,6 +100,7 @@ function PlayerNumberInput({
readOnly={readOnly}
disabled={disabled || locked}
onChange={debounceOnChange}
placeholder={placeholderText}
/>
);
}
Expand All @@ -112,7 +119,10 @@ registerComponent(
required: true,
returnType: ['SNumberDescriptor', 'number'],
}),
label: schemaProps.scriptString({ label: 'Label' }),
placeholder: schemaProps.scriptString({
label: 'Placeholder',
richText: false,
}),
onVariableChange: onVariableChangeSchema('On change action'),
...validatorSchema,
...classStyleIdSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ interface PlayerNumberSliderProps extends WegasComponentProps {
* Can be a boolean or a formatting function that takes the value and return a string
*/
displayValues?: DisplayMode;
/**
* placeholder - the grey text inside the box when nothing is written
*/
placeholder?: IScript;
onVariableChange?: OnVariableChange;
}

Expand All @@ -58,6 +62,7 @@ function PlayerNumberSlider({
className,
style,
id,
placeholder,
onVariableChange,
options,
...restProps
Expand All @@ -69,6 +74,8 @@ function PlayerNumberSlider({
script,
context,
);
const placeholderText = useScript<string>(placeholder, context);


const value = useStore(() =>
entityIs(number, 'NumberDescriptor')
Expand Down Expand Up @@ -133,6 +140,7 @@ function PlayerNumberSlider({
}
disabled={options.disabled || options.locked}
readOnly={options.readOnly}
placeholder={placeholderText}
/>
);
}
Expand All @@ -159,6 +167,10 @@ registerComponent(
label: 'Display value',
values: displayModes,
}),
placeholder: schemaProps.scriptString({
label: 'Placeholder',
richText: false,
}),
onVariableChange: onVariableChangeSchema('On number change action'),
...classStyleIdSchema,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {

interface PlayerStringInput
extends WegasComponentProps,
ValidatorComponentProps {
ValidatorComponentProps {
onVariableChange?: OnVariableChange;
/**
* script - the script that returns the variable to display and modify
Expand Down Expand Up @@ -150,7 +150,7 @@ registerComponent(
}),
placeholder: schemaProps.scriptString({
label: 'Placeholder',
richText: true,
richText: false,
}),
onVariableChange: onVariableChangeSchema('On text change action'),
rows: {
Expand Down