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

refactor: 🔥 Remove neutral color for ValidationMessage #2895

Merged
merged 6 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions .changeset/fresh-planes-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@digdir/designsystemet-css": patch
---

Remove `neutral` color on `ValidationMessage`
5 changes: 5 additions & 0 deletions .changeset/weak-keys-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@digdir/designsystemet-react": patch
---

fix: `ValidationMessage` should now have correct default element type
mimarz marked this conversation as resolved.
Show resolved Hide resolved
10 changes: 0 additions & 10 deletions packages/css/src/validation-message.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,4 @@
--dsc-validation-message-icon-url: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' d='M3.25 4A.75.75 0 0 1 4 3.25h16a.75.75 0 0 1 .75.75v16a.75.75 0 0 1-.75.75H4a.75.75 0 0 1-.75-.75zM11 7.75a1 1 0 1 1 2 0 1 1 0 0 1-2 0m-1.25 3a.75.75 0 0 1 .75-.75H12a.75.75 0 0 1 .75.75v4.75h.75a.75.75 0 0 1 0 1.5h-3a.75.75 0 0 1 0-1.5h.75v-4h-.75a.75.75 0 0 1-.75-.75'/%3E%3C/svg%3E");
--dsc-validation-message-color: var(--ds-color-info-text-subtle);
}

&[data-color='neutral'] {
--dsc-validation-message-icon-url: unset;
--dsc-validation-message-color: unset; /* This does not set the color to "neutral". This will inherit the closest `color` set. */
--dsc-validation-message-gap: 0; /* We don't display an icon for this */

&::before {
display: none;
}
}
}
17 changes: 10 additions & 7 deletions packages/react/src/components/Field/FieldCounter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { forwardRef, useEffect, useRef, useState } from 'react';
import { Paragraph } from '../Paragraph';
import {
ValidationMessage,
type ValidationMessageProps,
Expand Down Expand Up @@ -57,13 +58,15 @@ export const FieldCounter = forwardRef<HTMLParagraphElement, FieldCounterProps>(
>
{hasExceededLimit && label(over, remainder)}
</div>
<ValidationMessage
data-color={hasExceededLimit ? 'danger' : 'neutral'}
ref={ref}
{...rest}
>
{label(hasExceededLimit ? over : under, remainder)}
</ValidationMessage>
{hasExceededLimit ? (
<ValidationMessage ref={ref} {...rest}>
{label(over, remainder)}
</ValidationMessage>
) : (
<Paragraph ref={ref} {...rest} data-field='validation'>
{label(under, remainder)}
</Paragraph>
)}
</>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type ValidationMessageProps = MergeRight<
* Sets color and icon.
* @default 'danger'
*/
'data-color'?: SeverityColors | 'neutral';
'data-color'?: SeverityColors;
/**
* Change the default rendered element for the one passed as a child, merging their props and behavior.
* @default false
Expand All @@ -27,7 +27,7 @@ export const ValidationMessage = forwardRef<
HTMLParagraphElement,
ValidationMessageProps
>(function ValidationMessage({ className, asChild, ...rest }, ref) {
const Component = asChild ? Slot : 'div';
const Component = asChild ? Slot : 'p';

return (
<Component
Expand Down
Loading