Skip to content

Commit

Permalink
Add TailwindCheckbox
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Sep 26, 2021
1 parent 4131a35 commit 1c8a1d6
Show file tree
Hide file tree
Showing 16 changed files with 494 additions and 0 deletions.
12 changes: 12 additions & 0 deletions examples/checkbox-example/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
"root": true,
"extends": [
"lxsmnsyc/typescript/react"
],
"parserOptions": {
"project": "./tsconfig.eslint.json",
"tsconfigRootDir": __dirname,
},
"rules": {
}
};
5 changes: 5 additions & 0 deletions examples/checkbox-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local
15 changes: 15 additions & 0 deletions examples/checkbox-example/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions examples/checkbox-example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
28 changes: 28 additions & 0 deletions examples/checkbox-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "checkbox-example",
"version": "0.6.4",
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview"
},
"devDependencies": {
"autoprefixer": "^10.2.6",
"babel-preset-solid": "^1.1.1",
"eslint": "^7.32.0",
"eslint-config-lxsmnsyc": "^0.2.3",
"postcss": "^8.3.5",
"typescript": "^4.3.2",
"vite": "^2.4.4",
"vite-plugin-solid": "^2.0.1"
},
"dependencies": {
"solid-headless": "0.6.4",
"solid-js": "^1.1.0",
"tailwindcss": "^2.2.4"
},
"private": true,
"publishConfig": {
"access": "restricted"
}
}
6 changes: 6 additions & 0 deletions examples/checkbox-example/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
}
};
113 changes: 113 additions & 0 deletions examples/checkbox-example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import {
TailwindDialog,
TailwindDialogPanel,
TailwindDialogTitle,
TailwindTransition,
TailwindTransitionChild,
TailwindDialogOverlay,
TailwindCheckbox,
TailwindCheckboxIndicator,
TailwindCheckboxLabel,
TailwindCheckboxDescription,
} from 'solid-headless';
import { createSignal, JSX, Switch, Match } from 'solid-js';

function CheckIcon(props: JSX.IntrinsicElements['svg']): JSX.Element {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
{...props}
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2" d="M5 13l4 4L19 7"
/>
</svg>
);
}

function CloseIcon(props: JSX.IntrinsicElements['svg']): JSX.Element {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
{...props}
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width={2}
d="M6 18L18 6M6 6l12 12"
/>
</svg>
);
}

function UndefinedIcon(props: JSX.IntrinsicElements['svg']): JSX.Element {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
{...props}
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M20 12H4"
/>
</svg>
);
}

export default function App(): JSX.Element {
const [checked, setChecked] = createSignal<boolean>();

return (
<>
<div class="fixed inset-0 flex items-center justify-center">
<TailwindCheckbox
checked={checked()}
onChange={setChecked}
as="div"
class="flex flex-row justify-between items-center space-x-4"
>
<TailwindCheckboxIndicator
class="flex-none w-6 h-6 p-1 text-white bg-opacity-25 bg-fuchsia-900 rounded-full focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75"
>
<Switch>
<Match when={checked() === undefined}>
<span class="sr-only">Mixed</span>
<UndefinedIcon />
</Match>
<Match when={checked() === true}>
<span class="sr-only">Checked</span>
<CheckIcon />
</Match>
<Match when={checked() === false}>
<span class="sr-only">Unchecked</span>
<CloseIcon />
</Match>
</Switch>
</TailwindCheckboxIndicator>
<div class="flex-1 flex flex-col text-white">
<TailwindCheckboxLabel class="font-bold">
This is a checkbox label
</TailwindCheckboxLabel>
<TailwindCheckboxDescription class="font-semibold text-xs opacity-50">
This is a checkbox description
</TailwindCheckboxDescription>
</div>
</TailwindCheckbox>
</div>
</>
);
}
20 changes: 20 additions & 0 deletions examples/checkbox-example/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { render } from 'solid-js/web';
import App from './App';

import './style.css';

function Root() {
return (
<div className="bg-gradient-to-r from-pink-400 to-fuchsia-500 w-screen h-screen flex overflow-hidden">
<div className="flex flex-col items-center justify-center w-full">
<App />
</div>
</div>
);
}

const app = document.getElementById('app');

if (app) {
render(() => <Root />, app);
}
3 changes: 3 additions & 0 deletions examples/checkbox-example/src/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
1 change: 1 addition & 0 deletions examples/checkbox-example/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
19 changes: 19 additions & 0 deletions examples/checkbox-example/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const colors = require('tailwindcss/colors');

module.exports = {
mode: 'jit',
purge: [
'./src/**/*.tsx',
],
darkMode: 'class', // or 'media' or 'class'
theme: {
extend: {
colors: {
...colors,
},
},
},
variants: {},
plugins: [
],
};
19 changes: 19 additions & 0 deletions examples/checkbox-example/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"lib": ["ESNext", "DOM"],
"moduleResolution": "Node",
"strict": true,
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"jsx": "preserve",
"jsxImportSource": "solid-js",
},
"include": ["./src"]
}
19 changes: 19 additions & 0 deletions examples/checkbox-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"lib": ["ESNext", "DOM"],
"moduleResolution": "Node",
"strict": true,
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"jsx": "preserve",
"jsxImportSource": "solid-js",
},
"include": ["./src"]
}
6 changes: 6 additions & 0 deletions examples/checkbox-example/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'vite';
import solidPlugin from 'vite-plugin-solid';

export default defineConfig({
plugins: [solidPlugin()],
});
10 changes: 10 additions & 0 deletions packages/solid-headless/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,13 @@ export {
ToasterListener,
useToaster,
} from './tailwind/Toast';
export {
TailwindCheckbox,
TailwindCheckboxDescription,
TailwindCheckboxDescriptionProps,
TailwindCheckboxIndicator,
TailwindCheckboxIndicatorProps,
TailwindCheckboxLabel,
TailwindCheckboxLabelProps,
TailwindCheckboxProps,
} from './tailwind/Checkbox';
Loading

0 comments on commit 1c8a1d6

Please sign in to comment.