Skip to content

Commit

Permalink
Add toggleProps options
Browse files Browse the repository at this point in the history
  • Loading branch information
kapantzak committed Nov 20, 2024
1 parent 8f8b385 commit 6235e5a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
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 6235e5a

Please sign in to comment.