Skip to content

Commit

Permalink
Merge pull request #377 from ably/checkbox-and-toggles
Browse files Browse the repository at this point in the history
[WEB-3846] Add Toggles and prioritise disabled state for Checkboxes
  • Loading branch information
jamiehenson authored Jun 13, 2024
2 parents 6221b2f + 0b20710 commit 4b68b87
Show file tree
Hide file tree
Showing 11 changed files with 445 additions and 619 deletions.
1 change: 0 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const config: StorybookConfig = {
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-interactions",
"@chromatic-com/storybook",
],

docs: {},
Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
"tailwind.extend.js"
],
"devDependencies": {
"@chromatic-com/storybook": "^1",
"@mrtkrcm/cypress-plugin-snapshots": "https://github.com/mrtkrcm/cypress-plugin-snapshots#v1.13.0",
"@storybook/addon-essentials": "^8.1.4",
"@storybook/addon-interactions": "^8.1.4",
"@storybook/addon-links": "^8.1.4",
"@storybook/blocks": "^8.1.4",
"@storybook/react": "^8.1.4",
"@storybook/react-vite": "^8.1.4",
"@storybook/test": "^8.1.4",
"@storybook/addon-essentials": "^8.1.7",
"@storybook/addon-interactions": "^8.1.7",
"@storybook/addon-links": "^8.1.7",
"@storybook/blocks": "^8.1.7",
"@storybook/react": "^8.1.7",
"@storybook/react-vite": "^8.1.7",
"@storybook/test": "^8.1.7",
"@swc/cli": "^0.3.10",
"@swc/core": "^1.4.11",
"@typescript-eslint/eslint-plugin": "^6.21.0",
Expand All @@ -39,7 +38,7 @@
"msw": "2.3.1",
"msw-storybook-addon": "^2.0.2",
"prettier": "^3.2.5",
"storybook": "^8.1.4",
"storybook": "^8.1.7",
"svg-sprite": "^2.0.4",
"tailwindcss": "^3.3.6",
"typescript": "5.4.5",
Expand Down
2 changes: 1 addition & 1 deletion public/mockServiceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* - Please do NOT serve this file on production.
*/

const PACKAGE_VERSION = '2.3.0'
const PACKAGE_VERSION = '2.3.1'
const INTEGRITY_CHECKSUM = '26357c79639bfa20d64c0efca2a87423'
const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
const activeClientIds = new Set()
Expand Down
1 change: 1 addition & 0 deletions src/core/styles.components.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@import "./styles/layout.css";
@import "./styles/text.css";
@import "./styles/forms.css";
@import "./styles/toggles.css";

@layer components {
.ui-input {
Expand Down
8 changes: 4 additions & 4 deletions src/core/styles/forms.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
@apply text-p2 font-medium text-cool-black;
}

.ui-checkbox-input:disabled + .ui-checkbox-styled {
@apply bg-gui-unavailable border;
}

.ui-checkbox-input:focus + .ui-checkbox-styled {
border-width: 0.125rem;
@apply border-gui-focus;
Expand All @@ -48,6 +44,10 @@
@apply block;
}

.ui-checkbox-input:disabled + .ui-checkbox-styled {
@apply bg-gui-unavailable border;
}

.ui-textarea {
@apply font-sans font-medium text-cool-black text-p1;
@apply p-input mb-16;
Expand Down
38 changes: 38 additions & 0 deletions src/core/styles/toggles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@layer components {
.ui-toggle {
@apply h-32 w-[56px] rounded-full relative inline-block;
}

.ui-toggle:has(:disabled) {
@apply pointer-events-none;
}

.ui-toggle input {
@apply w-0 h-0 opacity-0;
}

.ui-toggle-slider {
@apply absolute cursor-pointer inset-0 transition-all bg-neutral-600 rounded-full;
}

.ui-toggle-slider:before {
@apply absolute h-[28px] w-[28px] left-2 bottom-2 bg-white rounded-full transition-transform drop-shadow-toggle;
content: "";
}

.ui-toggle input:checked + .ui-toggle-slider {
@apply bg-orange-600;
}

.ui-toggle input:disabled + .ui-toggle-slider {
@apply bg-gui-unavailable;
}

.ui-toggle input:checked + .ui-toggle-slider:before {
@apply translate-x-24;
}

.ui-toggle input:disabled + .ui-toggle-slider:before {
@apply bg-neutral-500;
}
}
50 changes: 48 additions & 2 deletions src/pages/Forms.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import Icon from "../core/Icon";
<h4 className="ui-text-h3 mb-16">
Checkboxes with P2 size text and tighter spacing
</h4>
<div className="flex items-start mb-12">
<div className="ui-checkbox-p2">
<input
data-ui-checkbox-native=""
type="checkbox"
Expand All @@ -108,7 +108,7 @@ import Icon from "../core/Icon";
this privacy policy.
</label>
</div>
<div className="flex items-start mb-12">
<div className="ui-checkbox-p2">
<input
data-ui-checkbox-native=""
type="checkbox"
Expand Down Expand Up @@ -150,6 +150,52 @@ import Icon from "../core/Icon";
</label>
</div>
</div>
<div className="mb-40">
<h4 className="ui-text-h3 mb-16">Disabled checkboxes</h4>
<div className="ui-checkbox-p2">
<input
data-ui-checkbox-native=""
type="checkbox"
id="checkbox-example-7"
name="checkbox-example-7"
value="yes"
className="ui-checkbox-input"
disabled
/>
<div data-ui-checkbox-styled="" className="ui-checkbox-styled">
<Icon
name="icon-gui-tick"
size="1rem"
additionalCSS="ui-checkbox-styled-tick"
/>
</div>
<label htmlFor="checkbox-example-7" className="ui-checkbox-label-p2">
Disabled checkbox
</label>
</div>
<div className="ui-checkbox-p2">
<input
data-ui-checkbox-native=""
type="checkbox"
id="checkbox-example-8"
name="checkbox-example-8"
value="yes"
className="ui-checkbox-input"
checked
disabled
/>
<div data-ui-checkbox-styled="" className="ui-checkbox-styled">
<Icon
name="icon-gui-tick"
size="1rem"
additionalCSS="ui-checkbox-styled-tick"
/>
</div>
<label htmlFor="checkbox-example-8" className="ui-checkbox-label-p2">
Disabled checkbox with a checked state
</label>
</div>
</div>
<h3 className="ui-text-h2 mb-24">Textarea</h3>
<div className="mb-40">
<label className="ui-text-p1 block mb-24" htmlFor="example-text-area">
Expand Down
42 changes: 42 additions & 0 deletions src/pages/Toggles.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Meta, Unstyled } from "@storybook/blocks";
import { togglesHtml } from "./utils.ts";
import Code from "../core/Code";

<Meta title="Brand/Toggles" />

<Unstyled>
<h1 className="ui-text-h1 mb-32">Toggles</h1>

<div className="flex items-center gap-24 mb-24">
<label className="ui-toggle">
<input type="checkbox" />
<span className="ui-toggle-slider"></span>
</label>
Default
</div>
<div className="flex items-center gap-24 mb-24">
<label className="ui-toggle">
<input type="checkbox" checked />
<span className="ui-toggle-slider"></span>
</label>
Toggled
</div>
<div className="flex items-center gap-24 mb-24">
<label className="ui-toggle">
<input type="checkbox" disabled />
<span className="ui-toggle-slider"></span>
</label>
Disabled
</div>
<div className="flex items-center gap-24 mb-24">
<label className="ui-toggle">
<input type="checkbox" />
<span className="ui-toggle-slider bg-neutral-800"></span>
</label>
Customised slider colour
</div>
<div className="ui-divider-spacing">
<h4 className="ui-text-h3 mb-16">Example HTML</h4>
<Code language="html" snippet={togglesHtml} />
</div>
</Unstyled>
10 changes: 10 additions & 0 deletions src/pages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,13 @@ export const formsHtml = `
<label for="checkbox-example" class="ui-checkbox-label-p1">Yes</label>
</div>
`;

export const togglesHtml = `
<div className="flex items-center gap-24 mb-16">
<label className="ui-toggle">
<input type="checkbox" />
<span className="ui-toggle-slider"></span>
</label>
Default
</div>
`;
3 changes: 3 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ module.exports = {
quote: "0rem 1.5rem 2rem 0rem #0000000d",
// opacity
},
dropShadow: {
toggle: ["0 4px 4px rgba(0,0,0,0.25)", "0 4px 8px rgba(0,0,0,0.15)"],
},
letterSpacing: {
"tighten-0.025": "var(--ls-tighten-0_025)",
"tighten-0.02": "var(--ls-tighten-0_02)",
Expand Down
Loading

0 comments on commit 4b68b87

Please sign in to comment.