Skip to content

Commit 3f8be0e

Browse files
Tailwind config in submodule
1 parent 6f6b0b7 commit 3f8be0e

File tree

5 files changed

+232
-6
lines changed

5 files changed

+232
-6
lines changed

components/Buttons.tsx

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,46 @@
1+
import '../tailwind.config.js'
2+
import { ButtonProps, KernButtonProps } from '../types/buttons.js';
13

2-
3-
export function TestButton() {
4+
function combineClassNames(...classes: string[]) {
5+
return classes.filter(Boolean).join(' ')
6+
}
7+
export function KernButton(props: KernButtonProps) {
48
return (
59
<button
6-
type="button"
7-
className="inline-flex w-full justify-center rounded-md border border-transparent bg-red-600 px-4 py-2 text-base font-medium text-white shadow-sm hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 sm:ml-3 sm:w-auto sm:text-sm"
10+
type={props.buttonType || "button"}
11+
className={combineClassNames(
12+
props.className || "border-gray-300 bg-white text-gray-700 hover:bg-gray-50", // copy this, and replace it with a color if you want to change the color
13+
"items-center rounded-md border px-4 py-2.5 text-xs font-medium shadow-sm focus:outline-none",
14+
props.disabled ? "cursor-not-allowed opacity-50" : "cursor-pointer opacity-100"
15+
)}
16+
onClick={props.onClick}
17+
disabled={props.disabled}
818
>
9-
Delete
10-
19+
{props.icon && (
20+
<props.icon className="h-5 w-5 mr-2" aria-hidden="true" />
21+
)}
22+
{props.buttonName}
1123
</button>
1224
);
1325
}
26+
27+
28+
export function AddButton(props: ButtonProps) {
29+
return <KernButton buttonName="Add" disabled={props.disabled} onClick={props.onClick} className="border-green-400 bg-green-100 text-green-700 hover:bg-green-50" />;
30+
}
31+
32+
export function SaveButton(props: ButtonProps) {
33+
return <KernButton buttonName="Save" disabled={props.disabled} onClick={props.onClick} className="border-green-400 bg-green-100 text-green-700 hover:bg-green-50" />;
34+
}
35+
36+
export function DeleteButton(props: ButtonProps) {
37+
return <KernButton buttonName="Delete" onClick={props.onClick} />;
38+
}
39+
40+
export function CloseButton(props: ButtonProps) {
41+
return <KernButton buttonName="Close" onClick={props.onClick} />;
42+
}
43+
44+
export function RemoveButton(props: ButtonProps) {
45+
return <KernButton buttonName="Remove" onClick={props.onClick} />;
46+
}

components/Dropdown.tsx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { Fragment } from 'react'
2+
import { Menu, Transition } from '@headlessui/react'
3+
import { ChevronDownIcon } from '@heroicons/react/20/solid'
4+
import { combineClassNames } from '@/submodules/javascript-functions/general';
5+
import { DropdownProps, OptionProps } from '../types/dropdown';
6+
7+
8+
export default function Dropdown(props: DropdownProps) {
9+
const isDisabled = props.disabled || props.options.length < 1;
10+
return (
11+
<Menu as="div" className="relative inline-block text-left">
12+
<div>
13+
<Menu.Button className={`inline-flex w-full justify-center items-center rounded-md border border-gray-300
14+
bg-white px-4 py-2 text-sm font-medium text-gray-700 shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2
15+
focus:ring-gray-300 focus:ring-offset-2 focus:ring-offset-gray-100
16+
${isDisabled ? "opacity-50" : ""}`}
17+
disabled={isDisabled}
18+
>
19+
{props.buttonName}
20+
<ChevronDownIcon
21+
className="-mr-1 ml-2 h-5 w-5"
22+
aria-hidden="true"
23+
/>
24+
</Menu.Button>
25+
</div>
26+
<Transition
27+
as={Fragment}
28+
enter="transition ease-out duration-100"
29+
enterFrom="transform opacity-0 scale-95"
30+
enterTo="transform opacity-100 scale-100"
31+
leave="transition ease-in duration-75"
32+
leaveFrom="transform opacity-100 scale-100"
33+
leaveTo="transform opacity-0 scale-95"
34+
>
35+
<Menu.Items className="absolute z-10 mt-2 w-40 origin-top-right rounded-md bg-white shadow-sm ring-1 ring-black ring-opacity-5 focus:outline-none">
36+
<div className="py-1">
37+
{props.options.map((option: OptionProps) => (
38+
<div key={option.name}>
39+
<Menu.Item >
40+
{({ active }) => (
41+
<a key={option.id}
42+
className={combineClassNames(
43+
active ? "bg-gray-100 text-gray-900" : "text-gray-700",
44+
"block px-4 py-2 text-sm cursor-pointer"
45+
)}
46+
onClick={() => {
47+
props.selectedOption(option);
48+
}}
49+
>
50+
{option.name}
51+
</a>
52+
)}
53+
</Menu.Item>
54+
</div>
55+
56+
))}
57+
</div>
58+
</Menu.Items>
59+
</Transition>
60+
</Menu>
61+
);
62+
}

tailwind.config.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
const colors = require("tailwindcss/colors");
2+
3+
/** @type {import('tailwindcss').Config} */
4+
module.exports = {
5+
purge: {
6+
enabled: true,
7+
mode: "all",
8+
content: ["./src/**/*.{html,ts}"],
9+
safelist: [
10+
/data-theme$/,
11+
"hljs",
12+
"hljs-comment",
13+
"hljs-quote",
14+
"hljs-keyword",
15+
"hljs-selector-tag",
16+
"hljs-subst",
17+
"hljs-number",
18+
"hljs-literal",
19+
"hljs-variable",
20+
"hljs-template-variable",
21+
"hljs-tag",
22+
"hljs-attr",
23+
"hljs-string",
24+
"hljs-doctag",
25+
"hljs-title",
26+
"hljs-section",
27+
"hljs-selector-id",
28+
"hljs-subst",
29+
"hljs-type",
30+
"hljs-class",
31+
"hljs-name",
32+
"hljs-attribute",
33+
"hljs-regexp",
34+
"hljs-link",
35+
"hljs-symbol",
36+
"hljs-bullet",
37+
"hljs-built_in",
38+
"hljs-builtin-name",
39+
"hljs-meta",
40+
"hljs-deletion",
41+
"hljs-addition",
42+
"hljs-emphasis",
43+
"hljs-strong",
44+
"label-overlay-*",
45+
// /(from|via|to|border|bg|text)-(.*)-(\d{1}0{1,2})/, // all color options
46+
// /(border|bg|text)-(.*)-(100|200|400|700)/, colors with specific value & type
47+
// /(border|bg|text)-(red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(100|200|400|700)/,
48+
/(bg)-(red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(100|200)/,
49+
/(border)-(red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(400)/,
50+
/(text)-(red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-(700)/,
51+
/(text)-(red|yellow|green|blue|indigo)-(800)/,
52+
/(text)-(white|black)/,
53+
/(bg)-(gray)-(700)/,
54+
/(text)-(lime)-(300)/,
55+
],
56+
options: {
57+
keyframes: true,
58+
},
59+
},
60+
content: [
61+
"./src/**/*.{js,ts,jsx,tsx}",
62+
],
63+
theme: {
64+
colors: {
65+
black: colors.black,
66+
white: colors.white,
67+
gray: colors.gray,
68+
red: colors.red,
69+
orange: colors.orange,
70+
amber: colors.amber,
71+
yellow: colors.yellow,
72+
lime: colors.lime,
73+
green: colors.green,
74+
emerald: colors.emerald,
75+
teal: colors.teal,
76+
cyan: colors.cyan,
77+
sky: colors.sky,
78+
blue: colors.blue,
79+
indigo: colors.indigo,
80+
violet: colors.violet,
81+
purple: colors.purple,
82+
fuchsia: colors.fuchsia,
83+
pink: colors.pink,
84+
rose: colors.rose,
85+
},
86+
fontFamily: {
87+
Inter: ["Inter var", "sans-serif"],
88+
},
89+
extend: {
90+
colors: {
91+
kernindigo: {
92+
DEFAULT: "#0C052E",
93+
dark: "#06023b",
94+
darker: "#4F46E5",
95+
"darker-1": "#312E81",
96+
light: "#EEF2FF",
97+
"dark-1": "#0000F5",
98+
"dark-2": "#4338CA",
99+
},
100+
},
101+
fontFamily: {
102+
sans: ["Inter var"],
103+
},
104+
},
105+
},
106+
plugins: [],
107+
}

types/buttons.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export type KernButtonProps = {
2+
buttonName: string;
3+
onClick?: (event: any) => void;
4+
className?: string;
5+
icon?: any;
6+
disabled?: boolean;
7+
buttonType?: 'button' | 'submit' | 'reset';
8+
}
9+
10+
export type ButtonProps = {
11+
onClick?: (event?: any) => void;
12+
disabled?: boolean;
13+
}

types/dropdown.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export type DropdownProps = {
2+
options: OptionProps[];
3+
buttonName: string;
4+
disabled?: boolean;
5+
selectedOption: (event: any) => void;
6+
}
7+
8+
export type OptionProps = {
9+
name: string;
10+
id: string;
11+
}

0 commit comments

Comments
 (0)