@shipfox/react-ui 0.5.0 → 0.6.0

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.
Files changed (63) hide show
  1. package/.storybook/preview.tsx +11 -0
  2. package/.turbo/turbo-build.log +16 -3
  3. package/.turbo/turbo-check.log +2 -2
  4. package/.turbo/turbo-type.log +1 -1
  5. package/CHANGELOG.md +8 -0
  6. package/README.md +16 -0
  7. package/dist/build-css-entry.js +5 -0
  8. package/dist/build-css-entry.js.map +1 -0
  9. package/dist/components/code-block/code-block-footer.d.ts.map +1 -1
  10. package/dist/components/code-block/code-block-footer.js +29 -15
  11. package/dist/components/code-block/code-block-footer.js.map +1 -1
  12. package/dist/components/dynamic-item/dynamic-item.stories.js +1 -1
  13. package/dist/components/dynamic-item/dynamic-item.stories.js.map +1 -1
  14. package/dist/components/icon/icon.d.ts +1 -0
  15. package/dist/components/icon/icon.d.ts.map +1 -1
  16. package/dist/components/icon/icon.js +3 -2
  17. package/dist/components/icon/icon.js.map +1 -1
  18. package/dist/components/index.d.ts +1 -0
  19. package/dist/components/index.d.ts.map +1 -1
  20. package/dist/components/index.js +1 -0
  21. package/dist/components/index.js.map +1 -1
  22. package/dist/components/modal/index.d.ts +3 -0
  23. package/dist/components/modal/index.d.ts.map +1 -0
  24. package/dist/components/modal/index.js +3 -0
  25. package/dist/components/modal/index.js.map +1 -0
  26. package/dist/components/modal/modal.d.ts +37 -0
  27. package/dist/components/modal/modal.d.ts.map +1 -0
  28. package/dist/components/modal/modal.js +262 -0
  29. package/dist/components/modal/modal.js.map +1 -0
  30. package/dist/components/modal/modal.stories.js +497 -0
  31. package/dist/components/modal/modal.stories.js.map +1 -0
  32. package/dist/components/moving-border/index.d.ts +2 -0
  33. package/dist/components/moving-border/index.d.ts.map +1 -0
  34. package/dist/components/moving-border/index.js +3 -0
  35. package/dist/components/moving-border/index.js.map +1 -0
  36. package/dist/components/typography/text.d.ts.map +1 -1
  37. package/dist/components/typography/text.js +1 -1
  38. package/dist/components/typography/text.js.map +1 -1
  39. package/dist/hooks/index.d.ts +1 -0
  40. package/dist/hooks/index.d.ts.map +1 -1
  41. package/dist/hooks/index.js +1 -0
  42. package/dist/hooks/index.js.map +1 -1
  43. package/dist/hooks/useMediaQuery.d.ts +2 -0
  44. package/dist/hooks/useMediaQuery.d.ts.map +1 -0
  45. package/dist/hooks/useMediaQuery.js +74 -0
  46. package/dist/hooks/useMediaQuery.js.map +1 -0
  47. package/dist/styles.css +1 -0
  48. package/index.css +1 -1
  49. package/package.json +11 -7
  50. package/src/build-css-entry.ts +3 -0
  51. package/src/components/code-block/code-block-footer.tsx +37 -30
  52. package/src/components/dynamic-item/dynamic-item.stories.tsx +1 -1
  53. package/src/components/icon/icon.tsx +2 -0
  54. package/src/components/index.ts +1 -0
  55. package/src/components/modal/index.ts +23 -0
  56. package/src/components/modal/modal.stories.tsx +384 -0
  57. package/src/components/modal/modal.tsx +309 -0
  58. package/src/components/moving-border/index.ts +1 -0
  59. package/src/components/typography/text.tsx +9 -1
  60. package/src/hooks/index.ts +1 -0
  61. package/src/hooks/useMediaQuery.ts +87 -0
  62. package/tsconfig.build.json +7 -1
  63. package/vite.css.config.ts +30 -0
@@ -24,7 +24,15 @@ export type TextProps = PropsWithChildren<HTMLAttributes<HTMLParagraphElement>>
24
24
  bold?: boolean;
25
25
  };
26
26
 
27
- export function Text({children, className, size, as, compact, bold, ...props}: TextProps) {
27
+ export function Text({
28
+ children,
29
+ className,
30
+ size,
31
+ as,
32
+ compact = true,
33
+ bold = false,
34
+ ...props
35
+ }: TextProps) {
28
36
  const Component = as ?? 'p';
29
37
  return (
30
38
  <Component
@@ -1,4 +1,5 @@
1
1
  export * from './useCopyToClipboard';
2
+ export * from './useMediaQuery';
2
3
  export * from './useResolvedTheme';
3
4
  export * from './useShikiHighlight';
4
5
  export * from './useShikiStyleInjection';
@@ -0,0 +1,87 @@
1
+ import {useEffect, useState} from 'react';
2
+
3
+ class MediaQueryManager {
4
+ private queries = new Map<string, MediaQueryList>();
5
+ private listeners = new Map<string, Set<() => void>>();
6
+ private changeHandlers = new Map<string, () => void>();
7
+
8
+ getMatches(query: string): boolean {
9
+ if (typeof window === 'undefined') return false;
10
+
11
+ if (!this.queries.has(query)) {
12
+ this.queries.set(query, window.matchMedia(query));
13
+ this.listeners.set(query, new Set());
14
+ }
15
+
16
+ const mediaQuery = this.queries.get(query);
17
+ return mediaQuery ? mediaQuery.matches : false;
18
+ }
19
+
20
+ subscribe(query: string, callback: () => void): () => void {
21
+ if (typeof window === 'undefined') {
22
+ return () => {
23
+ // Cleanup function for SSR - no-op
24
+ };
25
+ }
26
+
27
+ if (!this.queries.has(query)) {
28
+ this.queries.set(query, window.matchMedia(query));
29
+ this.listeners.set(query, new Set());
30
+ }
31
+
32
+ const mediaQuery = this.queries.get(query);
33
+ const listeners = this.listeners.get(query);
34
+
35
+ if (!mediaQuery || !listeners) {
36
+ return () => {
37
+ // Cleanup function - no-op if query wasn't found
38
+ };
39
+ }
40
+
41
+ listeners.add(callback);
42
+
43
+ if (listeners.size === 1) {
44
+ const changeHandler = () => {
45
+ for (const cb of listeners) {
46
+ cb();
47
+ }
48
+ };
49
+ this.changeHandlers.set(query, changeHandler);
50
+ mediaQuery.addEventListener('change', changeHandler);
51
+ }
52
+
53
+ return () => {
54
+ listeners.delete(callback);
55
+
56
+ if (listeners.size === 0) {
57
+ const changeHandler = this.changeHandlers.get(query);
58
+ if (changeHandler) {
59
+ mediaQuery.removeEventListener('change', changeHandler);
60
+ this.changeHandlers.delete(query);
61
+ }
62
+ this.queries.delete(query);
63
+ this.listeners.delete(query);
64
+ }
65
+ };
66
+ }
67
+ }
68
+
69
+ const mediaQueryManager = new MediaQueryManager();
70
+
71
+ export function useMediaQuery(query: string): boolean {
72
+ const [matches, setMatches] = useState(() => mediaQueryManager.getMatches(query));
73
+
74
+ useEffect(() => {
75
+ const updateMatches = () => {
76
+ setMatches(mediaQueryManager.getMatches(query));
77
+ };
78
+
79
+ const unsubscribe = mediaQueryManager.subscribe(query, updateMatches);
80
+
81
+ updateMatches();
82
+
83
+ return unsubscribe;
84
+ }, [query]);
85
+
86
+ return matches;
87
+ }
@@ -9,5 +9,11 @@
9
9
  "types": ["@shipfox/vite/client"]
10
10
  },
11
11
  "include": ["src"],
12
- "exclude": ["**/*.test.tsx", "**/*.test.ts", "**/*.stories.tsx", "**/*.stories.ts"]
12
+ "exclude": [
13
+ "**/*.test.tsx",
14
+ "**/*.test.ts",
15
+ "**/*.stories.tsx",
16
+ "**/*.stories.ts",
17
+ "**/build-css-entry.ts"
18
+ ]
13
19
  }
@@ -0,0 +1,30 @@
1
+ import {dirname, resolve} from 'node:path';
2
+ import {fileURLToPath} from 'node:url';
3
+ import {defineConfig} from '@shipfox/vite';
4
+ import tailwindcss from '@tailwindcss/vite';
5
+ import react from '@vitejs/plugin-react';
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = dirname(__filename);
9
+
10
+ export default defineConfig(
11
+ {
12
+ plugins: [react(), tailwindcss()],
13
+ build: {
14
+ outDir: 'dist',
15
+ emptyOutDir: false,
16
+ cssCodeSplit: false,
17
+ rollupOptions: {
18
+ input: resolve(__dirname, 'src/build-css-entry.ts'),
19
+ output: {
20
+ entryFileNames: 'css-entry.js',
21
+ assetFileNames: 'styles.css',
22
+ },
23
+ },
24
+ },
25
+ css: {
26
+ minify: true,
27
+ },
28
+ },
29
+ import.meta.url,
30
+ );