aboutsummaryrefslogtreecommitdiff
path: root/packages/ui/src
diff options
context:
space:
mode:
authorPauline <git@ethanlibs.co>2023-10-14 22:27:27 -0400
committerPauline <git@ethanlibs.co>2023-10-14 22:27:27 -0400
commit2582162cea2b3a59cd21c78f8b73cb03d0acad40 (patch)
tree432057475f3b51850a85e2cba9969bcb79f3a8e6 /packages/ui/src
parent06f51ccdc496a6581d098edc424f3973e550221d (diff)
downloadNexus-2582162cea2b3a59cd21c78f8b73cb03d0acad40.tar.gz
Nexus-2582162cea2b3a59cd21c78f8b73cb03d0acad40.tar.bz2
Nexus-2582162cea2b3a59cd21c78f8b73cb03d0acad40.zip
refactor(trunk): refactor the entire project idk
Diffstat (limited to 'packages/ui/src')
-rw-r--r--packages/ui/src/index.ts1
-rw-r--r--packages/ui/src/keys.ts56
-rw-r--r--packages/ui/src/utils.tsx28
3 files changed, 85 insertions, 0 deletions
diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts
new file mode 100644
index 0000000..904db93
--- /dev/null
+++ b/packages/ui/src/index.ts
@@ -0,0 +1 @@
+export { cva, cx } from 'class-variance-authority';
diff --git a/packages/ui/src/keys.ts b/packages/ui/src/keys.ts
new file mode 100644
index 0000000..55940f9
--- /dev/null
+++ b/packages/ui/src/keys.ts
@@ -0,0 +1,56 @@
+export enum ModifierKeys {
+ Alt = 'Alt',
+ Shift = 'Shift',
+ AltGraph = 'AltGraph',
+ CapsLock = 'CapsLock',
+ Control = 'Control',
+ Fn = 'Fn',
+ FnLock = 'FnLock',
+ Meta = 'Meta',
+ NumLock = 'NumLock',
+ ScrollLock = 'ScrollLock',
+ Symbol = 'Symbol',
+ SymbolLock = 'SymbolLock'
+}
+
+export type OSforKeys = 'macOS' | 'Windows' | 'Other';
+
+export const modifierSymbols: Record<
+ ModifierKeys,
+ { macOS?: string; Windows?: string; Other: string }
+> = {
+ Alt: { macOS: '⌥', Other: 'Alt' },
+ AltGraph: { macOS: '⌥', Other: 'Alt' },
+ CapsLock: { Other: '⇪' },
+ Control: { macOS: '⌃', Other: 'Ctrl' },
+ Fn: { macOS: 'fn', Other: 'Fn' },
+ FnLock: { macOS: 'fn', Other: 'Fn' },
+ Meta: { macOS: '⌘', Windows: '⊞ Win', Other: 'Meta' },
+ NumLock: { macOS: '⇭', Other: 'Num' },
+ ScrollLock: { macOS: '⤓', Other: 'ScrLk' },
+ Shift: { Other: 'Shift', macOS: '⇧' },
+ Symbol: { macOS: '⎄', Other: 'Sym' },
+ SymbolLock: { macOS: '⎄', Other: 'Sym' }
+};
+
+export const keySymbols: Record<string, { macOS?: string; Windows?: string; Other: string }> = {
+ ' ': { Other: '␣' },
+ 'Tab': { macOS: '⇥', Other: '⭾' },
+ 'Enter': { macOS: '↩', Other: '↵' },
+ 'Escape': { macOS: '⎋', Other: 'Esc' },
+ 'Backspace': { macOS: '⌫', Other: '⟵' },
+ 'ArrowUp': { Other: '↑' },
+ 'ArrowDown': { Other: '↓' },
+ 'ArrowLeft': { Other: '←' },
+ 'ArrowRight': { Other: '→' },
+ 'Insert': { Other: 'Ins' },
+ 'Delete': { macOS: '⌦', Other: 'Del' },
+ 'Home': { macOS: '↖', Other: 'Home' },
+ 'End': { macOS: '↘', Other: 'End' },
+ 'PageUp': { macOS: '⇞', Other: 'PgUp' },
+ 'PageDown': { macOS: '⇟', Other: 'PgDn' },
+ 'Shift': { macOS: '⇧', Other: 'Shift' },
+ 'PrintScreen': { Other: 'PrtSc' },
+ 'ScrollLock': { macOS: '⤓', Other: 'ScrLk' },
+ 'Pause': { macOS: '⎉', Other: 'Pause' }
+};
diff --git a/packages/ui/src/utils.tsx b/packages/ui/src/utils.tsx
new file mode 100644
index 0000000..5ccb488
--- /dev/null
+++ b/packages/ui/src/utils.tsx
@@ -0,0 +1,28 @@
+import clsx from 'clsx';
+import React from 'react';
+
+const twFactory =
+ (element: any) =>
+ ([newClassNames, ..._]: TemplateStringsArray) =>
+ React.forwardRef(({ className, ...props }: any, ref) =>
+ React.createElement(element, {
+ ...props,
+ className: clsx(newClassNames, className),
+ ref
+ })
+ );
+
+type ClassnameFactory<T> = (s: TemplateStringsArray) => T;
+
+type TailwindFactory = {
+ [K in keyof JSX.IntrinsicElements]: ClassnameFactory<
+ React.ForwardRefExoticComponent<JSX.IntrinsicElements[K]>
+ >;
+} & {
+ <T>(c: T): ClassnameFactory<T>;
+};
+
+export const tw = new Proxy((() => {}) as unknown as TailwindFactory, {
+ get: (_, property: string) => twFactory(property),
+ apply: (_, __, [el]: [React.ReactElement]) => twFactory(el)
+});