Skip to content

Commit

Permalink
Add toggleProps options (#542)
Browse files Browse the repository at this point in the history
* Add toggleProps options

* v4.7.11
  • Loading branch information
kapantzak authored Nov 20, 2024
1 parent 8f8b385 commit a42f2e8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@netdata/netdata-ui",
"version": "4.7.10",
"version": "4.7.11",
"description": "netdata UI kit",
"main": "dist/index.js",
"module": "dist/es6/index.js",
Expand Down
6 changes: 3 additions & 3 deletions src/components/toggle/styled.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ export const StyledToggle = styled.div`
transform: translateY(-50%);
transition: ${({ withTransition }) => (withTransition ? "left 0.2s ease" : "unset")};
opacity: ${({ disabled }) => (disabled ? "0.4" : "1")};
background-color: ${({ colored, checked }) => {
if (!colored) return getColor("controlFocused")
return checked ? getColor("primary") : getColor("error")
background-color: ${({ colored, checked, checkedColor, uncheckedColor, defaultColor }) => {
if (!colored) return getColor(defaultColor || "controlFocused")
return checked ? getColor(checkedColor || "primary") : getColor(uncheckedColor || "error")
}};
}
Expand Down
34 changes: 34 additions & 0 deletions src/components/toggle/toggle.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { useState, useEffect } from "react"
import { Toggle } from "./toggle"
import { useCallback } from "react"

export const Basic = args => {
const [checked, setChecked] = useState(false)

const onChange = useCallback(() => setChecked(prev => !prev), [setChecked])

useEffect(() => {
setChecked(args.checked)
}, [args.checked])

return <Toggle {...args} checked={checked} onChange={onChange} />
}

export default {
component: Toggle,
args: {
checked: false,
disabled: false,
colored: true,
labelLeft: "Left",
labelRight: "Right",
},
argTypes: {
checked: { control: "boolean" },
disabled: { control: "boolean" },
colored: { control: "boolean" },
labelLeft: { control: "text" },
labelRight: { control: "text" },
toggleProps: { control: "object" },
},
}

0 comments on commit a42f2e8

Please sign in to comment.