Skip to content

Commit

Permalink
refactor: move ToggleSkeleton to TypeScript (#13451)
Browse files Browse the repository at this point in the history
* refactor: move toggle-skeleton to typescript

* docs: jsdoc for aria-label prop

* chore: update README.md
  • Loading branch information
gerzonc authored Apr 3, 2023
1 parent 357fe0e commit 19a70c2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,15 @@
"contributions": [
"code"
]
},
{
"login": "gerzonc",
"name": "Gerzon",
"avatar_url": "https://avatars.githubusercontent.com/u/36211892?v=4",
"profile": "https://github.com/gerzonc",
"contributions": [
"code"
]
}
],
"commitConvention": "none"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ check out our [Contributing Guide](/.github/CONTRIBUTING.md) and our
<td align="center"><a href="https://github.com/davesteinberg"><img src="https://avatars.githubusercontent.com/u/3935584?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Dave Steinberg</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=davesteinberg" title="Code">💻</a></td>
<td align="center"><a href="https://seongryoo.github.io"><img src="https://avatars.githubusercontent.com/u/106095943?s=96&v=4" width="100px;" alt=""/><br /><sub><b>Seong-Hyun Ryoo</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=shryoo-ibm" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/pratikkarad"><img src="https://avatars.githubusercontent.com/u/32093370?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Pratik Karad</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=pratikkarad" title="Code">💻</a> <a href="#a11y-pratikkarad" title="Accessibility">️️️️♿️</a></td>
<td align="center"><a href="https://github.com/gerzonc"><img src="https://avatars.githubusercontent.com/u/36211892?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Gerzon</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=gerzonc" title="Code">💻</a></td>
</tr>
</table>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,34 @@ import React from 'react';
import cx from 'classnames';
import { PrefixContext } from '../../internal/usePrefix';

class ToggleSkeleton extends React.Component {
type ToggleSkeletonProps = {
'aria-label': string;

/**
* Specify an optional className to add to the form item wrapper.
*/
className?: string;

/**
* Provide an id that unique represents the underlying `<input>`
*/
id?: string;

/**
* Provide the text that will be read by a screen reader when visiting this
* control
* `aria-label` is always required but will be null if `labelText` is also
* provided
*/
labelText?: string;

/**
* Specify the size of the Toggle. Currently only supports 'sm' or 'md' (default)
*/
size?: 'sm' | 'md';
} & React.HTMLAttributes<HTMLDivElement>;

class ToggleSkeleton extends React.Component<ToggleSkeletonProps> {
static propTypes = {
['aria-label']: PropTypes.string.isRequired,

Expand All @@ -26,7 +53,7 @@ class ToggleSkeleton extends React.Component {
/**
* Provide the text that will be read by a screen reader when visiting this
* control
* `aria-label` is always required but will be null if `labelText` is also
* `aria-label` is always required but will be undefined if `labelText` is also
* provided
*/
labelText: PropTypes.string,
Expand All @@ -37,7 +64,7 @@ class ToggleSkeleton extends React.Component {
size: PropTypes.oneOf(['sm', 'md']),
};

static defaultProps = {
static defaultProps: Partial<ToggleSkeletonProps> = {
['aria-label']: 'Toggle is loading',
size: 'md',
};
Expand Down Expand Up @@ -66,7 +93,7 @@ class ToggleSkeleton extends React.Component {
<label
className={`${prefix}--toggle-input__label`}
htmlFor={id}
aria-label={labelText ? null : this.props['aria-label']}>
aria-label={labelText ? undefined : this.props['aria-label']}>
{labelText ? <div>{labelText}</div> : null}
<span className={`${prefix}--toggle__switch`}>
<span className={`${prefix}--toggle__text--left`} />
Expand Down

0 comments on commit 19a70c2

Please sign in to comment.