Skip to content
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
9 changes: 2 additions & 7 deletions src/lib/components/Checkbox/Checkbox.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@ $partial-path: '<line x1="3" y1="12" x2="20" y2="12" stroke-width="2" stroke="cu
}

// size, box, gap, paddingV (in a form field), mark, mark viewBox
$sizes: (
("xs", 18, 6, 4, 16, "0 0 23 23"),
("sm", 20, 8, 6, 18, "0 0 23 23"),
("md", 24, 10, 8, 22, "-1 -1 24 24"),
("lg", 28, 12, 10, 24, "-1 -1 24 24")
);
$sizes: (("xs", 18, 6, 4, 16, "0 0 23 23"), ("sm", 20, 8, 6, 18, "0 0 23 23"), ("md", 24, 10, 8, 22, "-1 -1 24 24"), ("lg", 28, 12, 10, 24, "-1 -1 24 24"));

.Root {
display: inline-flex;
vertical-align: bottom;
align-items: center;
align-items: flex-start;
}

.input {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const Checkbox = (p: PropsWithRefAndChildren<CheckboxProps, HTMLDivElement>) =>
]);

return (
<div className={classNames} style={style} ref={ref} data-testid="checkbox">
<div className={classNames} style={style} ref={ref} data-testid="checkbox" data-mtf-inline-control>
<input
name={name}
id={id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`Checkbox should render with only required props, and have standard prop
<div>
<div
class="Root md"
data-mtf-inline-control="true"
data-testid="checkbox"
>
<input
Expand Down
72 changes: 48 additions & 24 deletions src/lib/components/Form/FormFields/FormField.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,46 @@
$sizes: (("xs", "xxs", 2, 8, 4, 20), ("sm", "xxs", 4, 12, 6, 24), ("md", "xs", 6, 16, 8, 28), ("lg", "sm", 8, 20, 10, 32));

.Root {
--mtf-form-field-helper-color: var(--mtf-color-text-softer);
display: flex;
}

// The required mark, always after the label
.required {
--mtf-form-field-mark: "*";
.error {
--mtf-form-field-helper-color: var(--mtf-color-danger-text);
}

.success {
--mtf-form-field-helper-color: var(--mtf-color-success-text);
}

.disabled {
--mtf-form-field-helper-color: var(--mtf-color-text-disabled);
}

.mark {
color: var(--mtf-form-field-helper-color);
}

.label {
color: var(--mtf-color-text-strong);

&::after {
content: var(--mtf-form-field-mark, none);
.required &::after {
content: "*";
padding: 0 var(--mtf-sizing-space-2);
color: var(--mtf-color-text-softer);
color: var(--mtf-form-field-helper-color);
font-weight: var(--mtf-typography-weight-strongest);
}

// After the base colors: same specificity, so error and disabled win by order
.error &::after {
color: var(--mtf-color-danger-text);
}

.disabled &,
.disabled &::after {
color: var(--mtf-color-text-disabled);
}
}

.helper {
color: var(--mtf-color-text-softer);
color: var(--mtf-form-field-helper-color);
white-space: pre-line;
@include transition(color);

.error & {
color: var(--mtf-color-danger-text);
}

.success & {
color: var(--mtf-color-success-text);
}

.disabled & {
color: var(--mtf-color-text-disabled);
}
}

.inputContainer {
Expand Down Expand Up @@ -122,6 +117,31 @@ $sizes: (("xs", "xxs", 2, 8, 4, 20), ("sm", "xxs", 4, 12, 6, 24), ("md", "xs", 6
}
}

// Edge case of labelless use where a required mark(asterisks) should also be placed:
.withMark {
// The control and the mark share the first line, the helper wraps to the next one
flex-flow: row wrap;
align-items: flex-start;

// A zero basis keeps the mark on the control's line, however wide the control is
> :first-child {
flex: 1 1 0;
min-width: 0;
}

// data-mtf-inline-control marks the controls as wide as their content (Checkbox, Switch, RadioGroup, PinCode), while
// the others fill the row. Such a control, or a group of only such controls, keeps its width, so the mark follows it
// instead of going to the row's end
> [data-mtf-inline-control],
> .groupItems:not(:has(> :not([data-mtf-inline-control]))) {
max-width: max-content;
}

> .helper {
flex-basis: 100%;
}
}

@each $size, $helperStep, $gapVLabel, $gapHLabel, $marginTopHLabel, $gapHGroupItems in $sizes {
.#{$size} {
&.verticalLabel {
Expand Down Expand Up @@ -151,6 +171,10 @@ $sizes: (("xs", "xxs", 2, 8, 4, 20), ("sm", "xxs", 4, 12, 6, 24), ("md", "xs", 6
@include typography("text-#{$size}", "strong");
}

.mark {
@include typography("text-#{$size}", "strongest");
}

.helper {
@include typography("text-#{$helperStep}", "regular");
}
Expand Down
10 changes: 8 additions & 2 deletions src/lib/components/Form/FormFields/FormField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useForm } from "@/components/Form/context/FormContext";
import { FieldContext } from "@/components/Form/context/FieldContext";
import { PropsWithRef } from "../../../types";
import { FormFieldProps } from "@/components/Form/FormFields/types";
import { sanitizeModuleRootClasses } from "../../../../utils/cssUtils";
import { sanitizeModuleRootClasses, sanitizeModuleClasses } from "../../../../utils/cssUtils";
import usePropsWithThemeDefaults from "../../../motif/hooks/usePropsWithThemeDefaults";

const FormField = (props: PropsWithRef<FormFieldProps, HTMLDivElement>) => {
Expand All @@ -23,6 +23,7 @@ const FormField = (props: PropsWithRef<FormFieldProps, HTMLDivElement>) => {
const [error, setError] = useState<string | undefined>(() => getInitialExternalError(name, disabled));

const isRequired = validations?.some(validation => validation.requiredValidation);
const showMark = isRequired && !label;
const classNames = useMemo(
() =>
sanitizeModuleRootClasses(styles, className, [
Expand All @@ -39,8 +40,13 @@ const FormField = (props: PropsWithRef<FormFieldProps, HTMLDivElement>) => {
<FieldContext value={{ fieldName: name, validations, disabled, readOnly, success, setFieldError: setError, error: !!error }}>
<div className={classNames} ref={ref} data-testid="formField" {...(label && { "data-has-label": "" })} style={style}>
{label && <span className={styles.label}>{label}</span>}
<div className={styles.inputContainer}>
<div className={sanitizeModuleClasses(styles, "inputContainer", showMark && "withMark")}>
{children}
{showMark && (
<span className={styles.mark} aria-hidden="true">
*
</span>
)}
{(error || helperText) && <span className={styles.helper}>{error ?? helperText}</span>}
</div>
</div>
Expand Down
10 changes: 8 additions & 2 deletions src/lib/components/Form/FormFields/FormFieldGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FieldContext } from "@/components/Form/context/FieldContext";
import { PropsWithRefAndChildren } from "../../../types";
import { FormFieldGroupProps } from "@/components/Form/FormFields/types";
import usePropsWithThemeDefaults from "../../../motif/hooks/usePropsWithThemeDefaults";
import { sanitizeModuleRootClasses } from "../../../../utils/cssUtils";
import { sanitizeModuleClasses, sanitizeModuleRootClasses } from "../../../../utils/cssUtils";

const FormFieldGroup = (props: PropsWithRefAndChildren<FormFieldGroupProps, HTMLDivElement>) => {
const formContext = useForm();
Expand All @@ -32,6 +32,7 @@ const FormFieldGroup = (props: PropsWithRefAndChildren<FormFieldGroupProps, HTML
const [error, setError] = useState<string | undefined>(() => getInitialExternalError(name, disabled));

const isRequired = groupValidations?.some(validation => validation.requiredValidation);
const showMark = isRequired && !label;

const classNames = useMemo(
() =>
Expand Down Expand Up @@ -61,8 +62,13 @@ const FormFieldGroup = (props: PropsWithRefAndChildren<FormFieldGroupProps, HTML
>
<div className={classNames} data-testid="formFieldGroup" ref={ref} style={style} {...(label && { "data-has-label": "" })}>
{label && <span className={styles.label}>{label}</span>}
<div className={styles.inputContainer}>
<div className={sanitizeModuleClasses(styles, "inputContainer", showMark && "withMark")}>
<div className={styles.groupItems}>{children}</div>
{showMark && (
<span className={styles.mark} aria-hidden="true">
*
</span>
)}
{(error || helperText) && <span className={styles.helper}>{error ?? helperText}</span>}
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion src/lib/components/InputNumber/InputNumber.module.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@use "@styles" as *;

.Root {
overflow: hidden;
Comment thread
aktasmehmet marked this conversation as resolved.
Resolved
@include retain-scoped-class;
}
8 changes: 6 additions & 2 deletions src/lib/components/Motif/InputText/InputText.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ $sizes: (("xs", 8, 4), ("sm", 12, 6), ("md", 16, 8), ("lg", 20, 10));

&.error {
box-shadow: inset 0 0 0 var(--mtf-sizing-1) var(--mtf-color-danger-border);
.iconRight { color: var(--mtf-color-danger-text); }
.iconRight {
color: var(--mtf-color-danger-text);
}
}

&.success {
box-shadow: inset 0 0 0 var(--mtf-sizing-1) var(--mtf-color-success-border);
.iconRight { color: var(--mtf-color-success-text); }
.iconRight {
color: var(--mtf-color-success-text);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/PinCode/PinCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const PinCodeComponent = (p: PropsWithRef<PinCodeProps, HTMLDivElement>) => {
const classNames = sanitizeModuleRootClasses(styles, className, [size, circle && "circle"]);

return (
<div className={classNames} style={style} ref={ref} data-testid="pinCode">
<div className={classNames} style={style} ref={ref} data-testid="pinCode" data-mtf-inline-control>
<PinCodeContext value={contextValues}>{renderPinCodeItems()}</PinCodeContext>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`PinCode should render with only required props, have default prop value
<div>
<div
class="Root md"
data-mtf-inline-control="true"
data-testid="pinCode"
>
<div
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/RadioGroup/RadioGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const RadioGroup = (p: PropsWithRef<RadioGroupProps, HTMLDivElement>) => {
const classNames = sanitizeModuleRootClasses(styles, className, [orientation, size, inFormField && "inFormField"]);

return (
<div className={classNames} ref={ref} style={style} role="radiogroup">
<div className={classNames} ref={ref} style={style} role="radiogroup" data-mtf-inline-control>
<RadioGroupContext value={contextValue}>{children}</RadioGroupContext>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`RadioGroup should render with only required props, and have standard pr
<div>
<div
class="Root vertical md"
data-mtf-inline-control="true"
role="radiogroup"
>
<div
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/Switch/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Switch = (p: PropsWithRef<SwitchProps, HTMLDivElement>) => {
]);

return (
<div className={classNames} ref={ref} style={style}>
<div className={classNames} ref={ref} style={style} data-mtf-inline-control>
<input
type="checkbox"
role="switch"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`Switch should render with only required props, have default prop values
<div>
<div
class="Root md"
data-mtf-inline-control="true"
>
<input
class="input"
Expand Down
Loading