Skip to content

Commit 14eab55

Browse files
committed
feat(CFormSwitch): add reverse option
1 parent 74116de commit 14eab55

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

packages/coreui-react/src/components/form/CFormSwitch.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ export interface CFormSwitchProps extends Omit<InputHTMLAttributes<HTMLInputElem
2121
* The element represents a caption for a component.
2222
*/
2323
label?: string | ReactNode
24+
/**
25+
* Put switch on the opposite side.
26+
*
27+
* @sinve 4.7.0
28+
*/
29+
reverse?: boolean
2430
/**
2531
* Size the component large or extra large. Works only with `switch`.
2632
*/
@@ -36,12 +42,13 @@ export interface CFormSwitchProps extends Omit<InputHTMLAttributes<HTMLInputElem
3642
}
3743

3844
export const CFormSwitch = forwardRef<HTMLInputElement, CFormSwitchProps>(
39-
({ className, id, invalid, label, size, type = 'checkbox', valid, ...rest }, ref) => {
45+
({ className, id, invalid, label, reverse, size, type = 'checkbox', valid, ...rest }, ref) => {
4046
return (
4147
<div
4248
className={classNames(
4349
'form-check form-switch',
4450
{
51+
'form-check-reverse': reverse,
4552
[`form-switch-${size}`]: size,
4653
'is-invalid': invalid,
4754
'is-valid': valid,
@@ -74,6 +81,7 @@ CFormSwitch.propTypes = {
7481
id: PropTypes.string,
7582
invalid: PropTypes.bool,
7683
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
84+
reverse: PropTypes.bool,
7785
size: PropTypes.oneOf(['lg', 'xl']),
7886
type: PropTypes.oneOf(['checkbox', 'radio']),
7987
valid: PropTypes.bool,

packages/docs/content/forms/switch.mdx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ import {
1212
CFormSwitch,
1313
} from '@coreui/react/src/index'
1414

15-
## Switches
15+
## About
16+
17+
React Switch Components are a type of UI component that allows users to toggle between two states, usually represented as "on" or "off", "enabled" or "disabled", or "checked" or "unchecked".
18+
19+
When a user interacts with the component by clicking or tapping on it, the switch toggles its state, triggering an action or changing the appearance of the component. This type of component is often used in forms, settings panels, and other places where users need to turn something on or off or choose between two options.
20+
21+
## Example
1622

1723
```jsx preview
1824
<CFormSwitch label="Default switch checkbox input" id="formSwitchCheckDefault"/>
@@ -21,14 +27,25 @@ import {
2127
<CFormSwitch label="Disabled checked switch checkbox input" id="formSwitchCheckCheckedDisabled" defaultChecked disabled/>
2228
```
2329

24-
### Sizes
30+
## Sizing
31+
32+
Larger or smaller react switches? Add `size="lg"` or `size="xl"` for additional sizes.
2533

2634
```jsx preview
2735
<CFormSwitch label="Default switch checkbox input" id="formSwitchCheckDefaultNormal"/>
2836
<CFormSwitch size="lg" label="Large switch checkbox input" id="formSwitchCheckDefaultLg"/>
2937
<CFormSwitch size="xl" label="Extra large switch checkbox input" id="formSwitchCheckDefaultXL"/>
3038
```
3139

40+
## Reverse
41+
42+
Put your switches on the opposite side by adding `reverse` boolean property.
43+
44+
```jsx preview
45+
<CFormSwitch reverse type="radio" id="reverseFormSwitch1" label="Reverse switch"/>
46+
<CFormSwitch reverse type="radio" id="reverseFormSwitch2" label="Disabled reverse switch" disabled/>
47+
```
48+
3249
## API
3350

3451
### CFormSwitch

0 commit comments

Comments
 (0)