{/* prettier-ignore */}
{/*
Copyright 2023 Comcast Cable Communications Management, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

SPDX-License-Identifier: Apache-2.0
\*/}

import { Meta, Title } from '@storybook/blocks';
import * as ToggleStories from './Toggle.stories';

<Meta title="Components/Toggle" />

# Toggle

A checkbox component with toggle slider behavior

## Source

https://github.com/rdkcentral/Lightning-UI-Components/blob/develop/packages/@lightningjs/ui-components/src/components/Toggle/Toggle.js

## Usage

The toggle state is determined by the `checked` property, which defaults to `false`

```js
import { Toggle } from '@lightningjs/ui-components';

class Example extends lng.Component {
  static _template() {
    return {
      Toggle: {
        type: Toggle
      }
    };
  }
}
```

The `checked` state can be programmatically changed with `toggle()`.

```js
this.tag('Toggle').toggle();
```

The `toggle()` method is chainable. Let's say your `Toggle` component has `checked=false`

```js
console.log(this.tag('Toggle').checked); //=> true
```

By default, the `onEnter()` method executes `toggle()`. To add or change functionality, override this method:

```js
this.tag('Toggle').onEnter = toggle => {
  // do stuff
  toggle.toggle();
};
```

## API

### Properties

| name     | type    | readonly | description                                    |
| -------- | ------- | -------- | ---------------------------------------------- |
| checked  | boolean | true     | toggle state                                   |
| disabled | boolean | false    | should the component be unavailable to toggle? |

### Style Properties

| name                   | type          | description                                                                                                                                                               |
| ---------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| backgroundColor        | string        | color of background when unchecked                                                                                                                                        |
| backgroundColorChecked | string        | color of background when checked                                                                                                                                          |
| knobHeight             | number        | height of Toggle knob                                                                                                                                                     |
| knobPadding            | number        | padding to apply around knob                                                                                                                                              |
| knobRadius             | number        | radius of Toggle knob                                                                                                                                                     |
| knobWidth              | number        | width of Toggle knob                                                                                                                                                      |
| knobColor              | string        | color of knob when unchecked                                                                                                                                              |
| knobColorChecked       | string        | color of knob when checked                                                                                                                                                |
| strokeColor            | string        | color of stroke                                                                                                                                                           |
| strokeRadius           | number\|array | set radius of Toggle, which, if not defined, will be calculated based on the radius of the knob and padding (if no radius is desired, it needs to explicitly be set to 0) |
| strokeWidth            | number        | thickness of stroke                                                                                                                                                       |

### Methods

#### toggle(): void

Toggles `checked` state and updates UI accordingly

#### onEnter(thisArg): void

Callback to be executed on <kbd>Enter</kbd> key down event. Calls `toggle()` by default.
