@taiv/ui 2.1.5 → 2.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,9 @@
1
- import React from 'react';
2
- import { TextInputProps } from '@mantine/core';
1
+ import type { TextInputProps } from '@mantine/core';
2
+ import type React from 'react';
3
3
  interface SearchBarProps extends TextInputProps {
4
4
  fullWidth?: boolean;
5
+ useHotkey?: boolean;
5
6
  }
6
- declare const SearchBar: ({ width, fullWidth, size, styles, ...props }: SearchBarProps) => React.JSX.Element;
7
+ declare const SearchBar: ({ width, fullWidth, size, styles, useHotkey, id, onKeyDown, value, ...props }: SearchBarProps) => React.JSX.Element;
7
8
  export { SearchBar };
8
9
  //# sourceMappingURL=SearchBar.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SearchBar.d.ts","sourceRoot":"","sources":["../../../../../src/components/Inputs/TextInputs/SearchBar/SearchBar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAO/C,UAAU,cAAe,SAAQ,cAAc;IAC7C,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,QAAA,MAAM,SAAS,GAAI,8CAA6D,cAAc,sBAmC7F,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"SearchBar.d.ts","sourceRoot":"","sources":["../../../../../src/components/Inputs/TextInputs/SearchBar/SearchBar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAS/B,UAAU,cAAe,SAAQ,cAAc;IAC7C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,QAAA,MAAM,SAAS,GAAI,+EAUhB,cAAc,sBAkGhB,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -1,31 +1,71 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { TextInput } from '../TextInput/TextInput';
2
+ import { useHotkeys, useId } from '@mantine/hooks';
3
3
  import { neutral, red } from '../../../../constants/colors';
4
4
  import { fontBase } from '../../../../constants/font';
5
5
  import { spacing } from '../../../../constants/spacing';
6
+ import { useIsMac, useTablet, useTouchDevice } from '../../../../hooks';
7
+ import { Text } from '../../../Typography/Text/Text';
6
8
  import { componentSizes } from '../shared/sizes';
7
- const SearchBar = ({ width, fullWidth = false, size = 'md', styles, ...props }) => {
9
+ import { TextInput } from '../TextInput/TextInput';
10
+ const SearchBar = ({ width, fullWidth = false, size = 'md', styles, useHotkey = false, id, onKeyDown, value, ...props }) => {
8
11
  const selectedSize = componentSizes[size || 'md'];
9
12
  const computedWidth = fullWidth ? '100%' : width || `${selectedSize.width}px`;
13
+ const inputId = useId(id);
14
+ const isTablet = useTablet();
15
+ const isTouchDevice = useTouchDevice();
16
+ const isMobile = isTablet || isTouchDevice;
17
+ const isMac = useIsMac();
18
+ const hotkeyEnabled = useHotkey && !isMobile;
19
+ const hasValue = Boolean(value);
20
+ useHotkeys(hotkeyEnabled
21
+ ? [
22
+ [
23
+ 'mod+K',
24
+ (event) => {
25
+ event.preventDefault();
26
+ const el = document.getElementById(inputId);
27
+ el === null || el === void 0 ? void 0 : el.focus();
28
+ el === null || el === void 0 ? void 0 : el.select();
29
+ },
30
+ ],
31
+ ]
32
+ : [], []);
33
+ const handleKeyDown = (event) => {
34
+ if (hotkeyEnabled && event.key === 'Escape')
35
+ event.currentTarget.blur();
36
+ onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
37
+ };
10
38
  const style = {
11
39
  input: {
12
40
  ...fontBase,
13
- fontSize: selectedSize.fontSize,
14
- color: neutral[200],
15
- border: `1px solid ${neutral[100]}`,
16
- borderRadius: '8px',
17
- height: `${selectedSize.height}px`,
18
- transition: 'all 200ms ease-in-out',
19
41
  '&[data-invalid]': {
20
- borderColor: red[200],
21
- color: neutral[200],
22
42
  '&::placeholder': {
23
43
  color: red[200],
24
44
  },
45
+ borderColor: red[200],
46
+ color: neutral[200],
25
47
  },
48
+ border: `1px solid ${neutral[100]}`,
49
+ borderRadius: '8px',
50
+ color: neutral[200],
51
+ fontSize: selectedSize.fontSize,
52
+ height: `${selectedSize.height}px`,
53
+ transition: 'all 200ms ease-in-out',
26
54
  },
55
+ ...(hotkeyEnabled
56
+ ? { rightSection: { justifyContent: 'flex-end', paddingRight: spacing.md } }
57
+ : {}),
27
58
  ...styles,
28
59
  };
29
- return (_jsx(TextInput, { placeholder: "Search", width: computedWidth, styles: style, icon: _jsx("i", { className: "fas fa-search", style: { fontSize: 14, marginLeft: spacing.xxs } }), size: 'lg', fullWidth: fullWidth, ...props }));
60
+ const hotkeyHint = hotkeyEnabled && !hasValue ? (_jsx(Text, { span: true, variant: 'label', color: '#adb5bd', sx: {
61
+ alignItems: 'center',
62
+ display: 'inline-flex',
63
+ letterSpacing: 0.5,
64
+ lineHeight: 1,
65
+ pointerEvents: 'none',
66
+ userSelect: 'none',
67
+ whiteSpace: 'nowrap',
68
+ }, children: isMac ? '⌘+K' : 'Ctrl+K' })) : undefined;
69
+ return (_jsx(TextInput, { fullWidth: fullWidth, icon: _jsx("i", { className: 'fas fa-search', style: { fontSize: 14, marginLeft: spacing.xxs } }), id: inputId, onKeyDown: handleKeyDown, placeholder: 'Search', rightSection: hotkeyHint, rightSectionWidth: hotkeyEnabled ? (isMac ? 50 : 66) : undefined, size: 'lg', styles: style, value: value, width: computedWidth, ...props }));
30
70
  };
31
71
  export { SearchBar };
@@ -4,6 +4,7 @@ declare const meta: Meta<typeof SearchBar>;
4
4
  export default meta;
5
5
  type Story = StoryObj<typeof meta>;
6
6
  export declare const Default: Story;
7
+ export declare const UseHotkey: Story;
7
8
  export declare const Variants: Story;
8
9
  export declare const Sizes: Story;
9
10
  export declare const States: Story;
@@ -1 +1 @@
1
- {"version":3,"file":"SearchBar.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/Inputs/TextInputs/SearchBar/SearchBar.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,SAAS,CA2FhC,CAAC;AAEF,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAiBrB,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,KAetB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,KAgBnB,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,KAiBpB,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,KA2BrC,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,KA6C3B,CAAC"}
1
+ {"version":3,"file":"SearchBar.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/Inputs/TextInputs/SearchBar/SearchBar.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,SAAS,CAmGhC,CAAC;AAEF,eAAe,IAAI,CAAC;AACpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC;AAEnC,eAAO,MAAM,OAAO,EAAE,KAiBrB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,KAavB,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,KAetB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,KAgBnB,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,KAiBpB,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,KA2BrC,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,KA6C3B,CAAC"}
@@ -70,6 +70,14 @@ const meta = {
70
70
  defaultValue: { summary: 'false' },
71
71
  },
72
72
  },
73
+ useHotkey: {
74
+ control: { type: 'boolean' },
75
+ description: '⌘K / Ctrl+K focuses this input from anywhere; shows a hint badge. Enable on one SearchBar per page.',
76
+ table: {
77
+ type: { summary: 'boolean' },
78
+ defaultValue: { summary: 'false' },
79
+ },
80
+ },
73
81
  width: {
74
82
  control: { type: 'number' },
75
83
  description: 'Custom width in pixels',
@@ -112,6 +120,20 @@ export const Default = {
112
120
  },
113
121
  },
114
122
  };
123
+ export const UseHotkey = {
124
+ args: {
125
+ useHotkey: true,
126
+ fullWidth: false,
127
+ placeholder: 'Search',
128
+ },
129
+ parameters: {
130
+ docs: {
131
+ source: {
132
+ code: `<SearchBar useHotkey value={query} onChange={handleSearch} />`,
133
+ },
134
+ },
135
+ },
136
+ };
115
137
  export const Variants = {
116
138
  render: () => (_jsxs(Group, { gap: "20px", children: [_jsx(SearchBar, { label: "Find Users", description: "Search by name, email, or username" }), _jsx(SearchBar, { placeholder: "Search products..." }), _jsx(SearchBar, { label: "Product Search", error: "Search query is too short" })] })),
117
139
  parameters: {
@@ -5,7 +5,7 @@ export { useScrollLock } from './useScrollLock';
5
5
  export { useElementSize, useIntersection, useListState, useResizeObserver, useTimeout, useDebouncedValue } from '@mantine/hooks';
6
6
  export { useForm } from '@mantine/form';
7
7
  export type { UseFormReturnType } from '@mantine/form';
8
- export { useMediaQuery, useScreenSize, useMobile, useTablet, useLaptop, useDesktop, useWide, useTouchDevice } from './useMediaQuery';
8
+ export { useMediaQuery, useScreenSize, useMobile, useTablet, useLaptop, useDesktop, useWide, useTouchDevice, useIsMac } from './useMediaQuery';
9
9
  export { useNotifications } from './useNotifications';
10
10
  export { useConfirmationModal } from './useConfirmationModal';
11
11
  export { useInfoModal } from './useInfoModal';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACjI,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACrI,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACjI,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC/I,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -4,7 +4,7 @@ export { useHeadroom } from './useHeadroom';
4
4
  export { useScrollLock } from './useScrollLock';
5
5
  export { useElementSize, useIntersection, useListState, useResizeObserver, useTimeout, useDebouncedValue } from '@mantine/hooks';
6
6
  export { useForm } from '@mantine/form';
7
- export { useMediaQuery, useScreenSize, useMobile, useTablet, useLaptop, useDesktop, useWide, useTouchDevice } from './useMediaQuery';
7
+ export { useMediaQuery, useScreenSize, useMobile, useTablet, useLaptop, useDesktop, useWide, useTouchDevice, useIsMac } from './useMediaQuery';
8
8
  export { useNotifications } from './useNotifications';
9
9
  export { useConfirmationModal } from './useConfirmationModal';
10
10
  export { useInfoModal } from './useInfoModal';
@@ -8,4 +8,5 @@ export declare const useLaptop: () => boolean;
8
8
  export declare const useDesktop: () => boolean;
9
9
  export declare const useWide: () => boolean;
10
10
  export declare const useTouchDevice: () => boolean;
11
+ export declare const useIsMac: () => boolean;
11
12
  //# sourceMappingURL=useMediaQuery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMediaQuery.d.ts","sourceRoot":"","sources":["../../src/hooks/useMediaQuery.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,eAAO,MAAM,aAAa,6BAAuB,CAAC;AAElD,eAAO,MAAM,aAAa,QAAO,MAAM,OAAO,WAW7C,CAAC;AAEF,eAAO,MAAM,SAAS,eAA8D,CAAC;AACrF,eAAO,MAAM,SAAS,eAA8D,CAAC;AACrF,eAAO,MAAM,SAAS,eAA8D,CAAC;AACrF,eAAO,MAAM,UAAU,eAA+D,CAAC;AACvF,eAAO,MAAM,OAAO,eAA4D,CAAC;AACjF,eAAO,MAAM,cAAc,eAA2C,CAAC"}
1
+ {"version":3,"file":"useMediaQuery.d.ts","sourceRoot":"","sources":["../../src/hooks/useMediaQuery.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,IAAI,oBAAoB,EAAS,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,eAAO,MAAM,aAAa,6BAAuB,CAAC;AAElD,eAAO,MAAM,aAAa,QAAO,MAAM,OAAO,WAW7C,CAAC;AAEF,eAAO,MAAM,SAAS,eAA8D,CAAC;AACrF,eAAO,MAAM,SAAS,eAA8D,CAAC;AACrF,eAAO,MAAM,SAAS,eAA8D,CAAC;AACrF,eAAO,MAAM,UAAU,eAA+D,CAAC;AACvF,eAAO,MAAM,OAAO,eAA4D,CAAC;AACjF,eAAO,MAAM,cAAc,eAA2C,CAAC;AAEvE,eAAO,MAAM,QAAQ,eAA4B,CAAC"}
@@ -1,4 +1,4 @@
1
- import { useMediaQuery as useMantineMediaQuery } from '@mantine/hooks';
1
+ import { useMediaQuery as useMantineMediaQuery, useOs } from '@mantine/hooks';
2
2
  import { breakpoints } from '../constants/breakpoints';
3
3
  export const useMediaQuery = useMantineMediaQuery;
4
4
  export const useScreenSize = () => {
@@ -22,3 +22,4 @@ export const useLaptop = () => useMediaQuery(`(max-width: ${breakpoints.LAPTOP}p
22
22
  export const useDesktop = () => useMediaQuery(`(max-width: ${breakpoints.DESKTOP}px)`);
23
23
  export const useWide = () => useMediaQuery(`(max-width: ${breakpoints.WIDE}px)`);
24
24
  export const useTouchDevice = () => useMediaQuery('(pointer: coarse)');
25
+ export const useIsMac = () => useOs() === 'macos';
package/package.json CHANGED
@@ -85,5 +85,5 @@
85
85
  "storybook": "storybook dev -p 6006"
86
86
  },
87
87
  "types": "dist/index.d.ts",
88
- "version": "2.1.5"
88
+ "version": "2.1.6"
89
89
  }