Skip to content

Commit

Permalink
Split Message into Error and Description
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Aug 2, 2024
1 parent 578bac7 commit b838979
Show file tree
Hide file tree
Showing 31 changed files with 440 additions and 151 deletions.
25 changes: 15 additions & 10 deletions docs/data/base/components/field/UnstyledFieldAsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ export default function UnstyledFieldAsync() {
<Field.Validity>
{(state) => {
if (loading) {
return <FieldMessage>Checking availability...</FieldMessage>;
return <FieldDescription>Checking availability...</FieldDescription>;
}

if (state.value === '') {
return <FieldMessage>Enter a name</FieldMessage>;
return <FieldDescription>Enter a name</FieldDescription>;
}

if (!state.validity.customError) {
return (
<FieldMessage data-type="success">
<FieldDescription data-type="success">
<strong>@{state.value}</strong> is available
</FieldMessage>
</FieldDescription>
);
}

return <FieldMessage data-type="error" show="customError" />;
return <FieldError show="customError" />;
}}
</Field.Validity>
</FieldRoot>
Expand Down Expand Up @@ -119,18 +119,23 @@ const FieldControl = styled(Field.Control)`
}
`;

const FieldMessage = styled(Field.Message)`
const FieldDescription = styled(Field.Description)`
font-size: 90%;
margin: 0;
margin-top: 4px;
line-height: 1.1;
color: #666;
&[data-type='error'] {
color: red;
}
&[data-type='success'] {
color: green;
}
`;

const FieldError = styled(Field.Error)`
display: block;
font-size: 90%;
margin: 0;
margin-top: 4px;
line-height: 1.1;
color: red;
`;
25 changes: 15 additions & 10 deletions docs/data/base/components/field/UnstyledFieldAsync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ export default function UnstyledFieldAsync() {
<Field.Validity>
{(state) => {
if (loading) {
return <FieldMessage>Checking availability...</FieldMessage>;
return <FieldDescription>Checking availability...</FieldDescription>;
}

if (state.value === '') {
return <FieldMessage>Enter a name</FieldMessage>;
return <FieldDescription>Enter a name</FieldDescription>;
}

if (!state.validity.customError) {
return (
<FieldMessage data-type="success">
<FieldDescription data-type="success">
<strong>@{state.value as string}</strong> is available
</FieldMessage>
</FieldDescription>
);
}

return <FieldMessage data-type="error" show="customError" />;
return <FieldError show="customError" />;
}}
</Field.Validity>
</FieldRoot>
Expand Down Expand Up @@ -119,18 +119,23 @@ const FieldControl = styled(Field.Control)`
}
`;

const FieldMessage = styled(Field.Message)`
const FieldDescription = styled(Field.Description)`
font-size: 90%;
margin: 0;
margin-top: 4px;
line-height: 1.1;
color: #666;
&[data-type='error'] {
color: red;
}
&[data-type='success'] {
color: green;
}
`;

const FieldError = styled(Field.Error)`
display: block;
font-size: 90%;
margin: 0;
margin-top: 4px;
line-height: 1.1;
color: red;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ export default function UnstyledFieldIntroduction() {
}

return (
<FieldMessage>Your name will be visible on your profile.</FieldMessage>
<FieldDescription>
Your name will be visible on your profile.
</FieldDescription>
);
}}
</Field.Validity>
<FieldMessage data-error show="valueMissing" />
<FieldMessage data-error show="customError" />
<FieldMessage data-error show="patternMismatch">
<FieldError show="valueMissing" />
<FieldError show="patternMismatch">
Only alphanumeric characters are allowed (a-z, A-Z, 0-9).
</FieldMessage>
</FieldError>
</FieldRoot>
);
}
Expand All @@ -50,9 +51,9 @@ const FieldControl = styled(Field.Control)`
}
`;

const FieldMessage = styled(Field.Message)`
const FieldDescription = styled(Field.Description)`
font-size: 90%;
margin: 0;
margin-bottom: 0;
margin-top: 4px;
line-height: 1.1;
color: #666;
Expand All @@ -61,3 +62,13 @@ const FieldMessage = styled(Field.Message)`
color: red;
}
`;

const FieldError = styled(Field.Error)`
display: block;
font-size: 90%;
margin: 0;
margin-bottom: 0;
margin-top: 4px;
line-height: 1.1;
color: red;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ export default function UnstyledFieldIntroduction() {
}

return (
<FieldMessage>Your name will be visible on your profile.</FieldMessage>
<FieldDescription>
Your name will be visible on your profile.
</FieldDescription>
);
}}
</Field.Validity>
<FieldMessage data-error show="valueMissing" />
<FieldMessage data-error show="customError" />
<FieldMessage data-error show="patternMismatch">
<FieldError show="valueMissing" />
<FieldError show="patternMismatch">
Only alphanumeric characters are allowed (a-z, A-Z, 0-9).
</FieldMessage>
</FieldError>
</FieldRoot>
);
}
Expand All @@ -50,9 +51,9 @@ const FieldControl = styled(Field.Control)`
}
`;

const FieldMessage = styled(Field.Message)`
const FieldDescription = styled(Field.Description)`
font-size: 90%;
margin: 0;
margin-bottom: 0;
margin-top: 4px;
line-height: 1.1;
color: #666;
Expand All @@ -61,3 +62,13 @@ const FieldMessage = styled(Field.Message)`
color: red;
}
`;

const FieldError = styled(Field.Error)`
display: block;
font-size: 90%;
margin: 0;
margin-bottom: 0;
margin-top: 4px;
line-height: 1.1;
color: red;
`;
18 changes: 4 additions & 14 deletions docs/data/base/components/field/UnstyledFieldPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,18 @@ function validate(value) {
export default function UnstyledFieldPassword() {
function handleValidate(value) {
const password = value;
const errors = validate(password);
return errors.length ? 'error' : null;
return validate(password);
}

return (
<Field.Root validate={handleValidate} validateOnChange>
<Field.Control type="password" />
<Field.Label>Password</Field.Label>
<Field.Message show="customError" render={<ul />} data-error>
<Field.Error render={<ul />}>
<Field.Validity>
{(state) => {
const password = state.value;
const errors = validate(password);

if (!errors.length) {
return null;
}

return errors.map((error) => <li key={error}>{error}</li>);
}}
{(state) => state.errors.map((error) => <li key={error}>{error}</li>)}
</Field.Validity>
</Field.Message>
</Field.Error>
</Field.Root>
);
}
18 changes: 4 additions & 14 deletions docs/data/base/components/field/UnstyledFieldPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,18 @@ function validate(value: string) {
export default function UnstyledFieldPassword() {
function handleValidate(value: unknown) {
const password = value as string;
const errors = validate(password);
return errors.length ? 'error' : null;
return validate(password);
}

return (
<Field.Root validate={handleValidate} validateOnChange>
<Field.Control type="password" />
<Field.Label>Password</Field.Label>
<Field.Message show="customError" render={<ul />} data-error>
<Field.Error render={<ul />}>
<Field.Validity>
{(state) => {
const password = state.value as string;
const errors = validate(password);

if (!errors.length) {
return null;
}

return errors.map((error) => <li key={error}>{error}</li>);
}}
{(state) => state.errors.map((error) => <li key={error}>{error}</li>)}
</Field.Validity>
</Field.Message>
</Field.Error>
</Field.Root>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Field.Root validate={handleValidate} validateOnChange>
<Field.Control type="password" />
<Field.Label>Password</Field.Label>
<Field.Error render={<ul />}>
<Field.Validity>
{(state) => state.errors.map((error) => <li key={error}>{error}</li>)}
</Field.Validity>
</Field.Error>
</Field.Root>
Loading

0 comments on commit b838979

Please sign in to comment.