-
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(form): FormMessageCounter component added to public API
- Loading branch information
Showing
4 changed files
with
77 additions
and
8 deletions.
There are no files selected for viewing
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,60 @@ | ||
import React, { HTMLAttributes, ReactElement, ReactNode } from "react"; | ||
import cn from "classnames"; | ||
import { bem } from "@react-md/utils"; | ||
|
||
const block = bem("rmd-form-message"); | ||
|
||
/** @remarks \@since 2.9.0 */ | ||
export interface FormMessageCounterProps | ||
extends HTMLAttributes<HTMLSpanElement> { | ||
/** | ||
* The children to display in the counter. This is normally a string like: | ||
* | ||
* @example | ||
* String Example | ||
* ```ts | ||
* `${min} / ${max}` | ||
* ``` | ||
*/ | ||
children: ReactNode; | ||
} | ||
|
||
/** | ||
* This component can be used to create a "counter" within the | ||
* {@link FormMessage} component. | ||
* | ||
* Note: This is really only useful when using the {@link FormMessage} component | ||
* without a {@link TextField}. | ||
* | ||
* @example | ||
* Example Usage | ||
* ```ts | ||
* interface ExampleProps { | ||
* min: number; | ||
* max: number; | ||
* } | ||
* | ||
* function Example({ min, max }: ExampleProps) { | ||
* return ( | ||
* <FormMessage disableWrap> | ||
* <FormMessageCounter> | ||
* {`${min} / ${max}`} | ||
* </FormMessageCounter> | ||
* </FormMessage> | ||
* ); | ||
* } | ||
* ``` | ||
* | ||
* @remarks \@since 2.9.0 | ||
*/ | ||
export function FormMessageCounter({ | ||
children, | ||
className, | ||
...props | ||
}: FormMessageCounterProps): ReactElement { | ||
return ( | ||
<span {...props} className={cn(block("counter"), className)}> | ||
{children} | ||
</span> | ||
); | ||
} |
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