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

Add toggleProps options #542

Merged
merged 2 commits into from
Nov 20, 2024
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
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 @@ -17,39 +17,39 @@
display: none;
`

export const StyledToggle = styled.div`
box-sizing: border-box;
width: 40px;
height: 20px;
background: ${props =>
props.disabled ? getColor("mainBackgroundDisabled") : getColor("mainBackground")};
border: 1px solid ${getColor("border")};
border-radius: 100px;
transition: ${({ withTransition }) => (withTransition ? "all 150ms" : "unset")};

display: block;
position: relative;

-webkit-tap-highlight-color: transparent;
flex-shrink: 0;
align-self: flex-start;
cursor: pointer;
pointer-events: ${({ disabled }) => (disabled ? "none" : "auto")};
&:after {
display: block;
position: absolute;
content: "";
width: 16px;
height: 16px;
border-radius: 50%;
left: 5%;
top: 50%;
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 }) => {

Check warning on line 50 in src/components/toggle/styled.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
if (!colored) return getColor(defaultColor || "controlFocused")

Check warning on line 51 in src/components/toggle/styled.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 51 in src/components/toggle/styled.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 51 in src/components/toggle/styled.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 51 in src/components/toggle/styled.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 51 in src/components/toggle/styled.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
return checked ? getColor(checkedColor || "primary") : getColor(uncheckedColor || "error")

Check warning on line 52 in src/components/toggle/styled.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 52 in src/components/toggle/styled.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 52 in src/components/toggle/styled.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 52 in src/components/toggle/styled.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 52 in src/components/toggle/styled.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 52 in src/components/toggle/styled.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 52 in src/components/toggle/styled.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}};
}

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 => {

Check warning on line 5 in src/components/toggle/toggle.stories.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
const [checked, setChecked] = useState(false)

Check warning on line 6 in src/components/toggle/toggle.stories.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

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

Check warning on line 8 in src/components/toggle/toggle.stories.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 8 in src/components/toggle/toggle.stories.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 8 in src/components/toggle/toggle.stories.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 8 in src/components/toggle/toggle.stories.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function

Check warning on line 8 in src/components/toggle/toggle.stories.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function

useEffect(() => {

Check warning on line 10 in src/components/toggle/toggle.stories.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
setChecked(args.checked)

Check warning on line 11 in src/components/toggle/toggle.stories.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}, [args.checked])

Check warning on line 12 in src/components/toggle/toggle.stories.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

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

Check warning on line 14 in src/components/toggle/toggle.stories.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

Check warning on line 15 in src/components/toggle/toggle.stories.js

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

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" },
},
}
Loading