-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Rename Form Field Character Counter to Character Count (#1363)
- Loading branch information
1 parent
a54d239
commit a5299db
Showing
18 changed files
with
100 additions
and
107 deletions.
There are no files selected for viewing
8 changes: 4 additions & 4 deletions
8
...ts/form-field-character-counter/README.md → .../src/components/character-count/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
<!-- @license CC0-1.0 --> | ||
|
||
# Form Field Character Counter | ||
# Character Count | ||
|
||
Help users know how much text they can enter when there is a limit on the number of characters. | ||
|
||
Users will get updates at a pace that works best for the way they interact with the textarea. This means: | ||
|
||
- sighted users will see a count message that updates as they type | ||
- sighted users will see a count message that updates as they type; | ||
- screen reader users will hear the count announcement when they stop typing. | ||
|
||
This component does not restrict the user from entering information. The user can enter more than the character limit, but are told they’ve entered too many characters. This lets them type or copy and paste their full answer, then edit it down. | ||
|
||
## Guidelines | ||
|
||
- Only use a character counter when there is a good reason for limiting the number of characters users can enter. | ||
- Only use a character count when there is a good reason for limiting the number of characters users can enter. | ||
For example, if there is an indication that users are likely to enter more information than they need to. | ||
Or when there is a legal or technical reason that means an entry must be no more than a certain number of characters. | ||
- If your users keep hitting the character limit imposed by the backend of your service then try to increase the limit rather than use a character counter. | ||
- If your users keep hitting the character limit imposed by the backend of your service then try to increase the limit rather than use a character count. |
20 changes: 20 additions & 0 deletions
20
packages/css/src/components/character-count/character-count.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright Gemeente Amsterdam | ||
*/ | ||
|
||
@import "../../common/text-rendering"; | ||
|
||
.ams-character-count { | ||
color: var(--ams-character-count-color); | ||
font-family: var(--ams-character-count-font-family); | ||
font-size: var(--ams-character-count-font-size); | ||
font-weight: var(--ams-character-count-font-weight); | ||
line-height: var(--ams-character-count-line-height); | ||
|
||
@include text-rendering; | ||
} | ||
|
||
.ams-character-count--error { | ||
color: var(--ams-character-count-error-color); | ||
} |
20 changes: 0 additions & 20 deletions
20
packages/css/src/components/form-field-character-counter/form-field-character-counter.scss
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @license EUPL-1.2+ | ||
* Copyright Gemeente Amsterdam | ||
*/ | ||
|
||
import clsx from 'clsx' | ||
import { forwardRef } from 'react' | ||
import type { ForwardedRef, HTMLAttributes } from 'react' | ||
|
||
export type CharacterCountProps = HTMLAttributes<HTMLDivElement> & { | ||
/** The current length of the field’s value. */ | ||
length: number | ||
/** The maximum length of the field’s value. */ | ||
maxLength: number | ||
} | ||
|
||
export const CharacterCount = forwardRef( | ||
({ className, length, maxLength, ...restProps }: CharacterCountProps, ref: ForwardedRef<HTMLDivElement>) => ( | ||
<div | ||
{...restProps} | ||
ref={ref} | ||
className={clsx('ams-character-count', length > maxLength && 'ams-character-count--error', className)} | ||
role="status" | ||
> | ||
{`${length} van ${maxLength} tekens`} | ||
</div> | ||
), | ||
) | ||
|
||
CharacterCount.displayName = 'CharacterCount' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<!-- @license CC0-1.0 --> | ||
|
||
# React Character Count component | ||
|
||
[Character Count documentation](../../../css/src/components/character-count/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { CharacterCount } from './CharacterCount' | ||
export type { CharacterCountProps } from './CharacterCount' |
37 changes: 0 additions & 37 deletions
37
packages/react/src/FormFieldCharacterCounter/FormFieldCharacterCounter.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../form-field-character-counter.tokens.json → ...omponents/ams/character-count.tokens.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
storybook/src/components/CharacterCount/CharacterCount.docs.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{/* @license CC0-1.0 */} | ||
|
||
import { Canvas, Controls, Markdown, Meta, Primary } from "@storybook/blocks"; | ||
import * as CharacterCountStories from "./CharacterCount.stories.tsx"; | ||
import README from "../../../../packages/css/src/components/character-count/README.md?raw"; | ||
|
||
<Meta of={CharacterCountStories} /> | ||
|
||
<Markdown>{README}</Markdown> | ||
|
||
<Primary /> | ||
|
||
<Controls /> | ||
|
||
## Error | ||
|
||
When the length exceeds the maximum length, the color of the text changes to red. | ||
|
||
<Canvas of={CharacterCountStories.Error} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
...ook/src/components/FormFieldCharacterCounter/FormFieldCharacterCounter.docs.mdx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters