@remember-web/mixin 0.1.6 → 0.1.7

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.
@@ -0,0 +1,18 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ColorThemeType, ThemeType } from '../colors';
3
+ export interface RUIContentProps {
4
+ customMixins?: ColorThemeType;
5
+ forceTheme?: ThemeType;
6
+ setTheme?: (theme: ThemeType) => void;
7
+ }
8
+ export interface RUIContextValue {
9
+ currentTheme: ThemeType;
10
+ setTheme: RUIContentProps['setTheme'];
11
+ }
12
+ /** theme과 setTheme은 사용하는 곳에서 주입,
13
+ * 기본적으로는 브라우저의 미디어쿼리를 통해서 light, dark를 결정 */
14
+ export declare function RUIProvider({ children, customMixins, forceTheme, setTheme, }: {
15
+ children: ReactNode;
16
+ } & RUIContentProps): import("react/jsx-runtime").JSX.Element;
17
+ export declare function useRUI(): RUIContextValue;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/provider/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAK1D,MAAM,WAAW,eAAe;IAC9B,YAAY,CAAC,EAAE,cAAc,CAAC;IAC9B,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;CACvC;AAED,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,SAAS,CAAC;IACxB,QAAQ,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC;CACvC;AAID;6CAC6C;AAC7C,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,QAAQ,GACT,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,GAAG,eAAe,2CAa3C;AAED,wBAAgB,MAAM,oBAQrB"}
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { type ColorThemeType, type ThemeType } from '../colors';
3
+ export declare const RUIGlobalStyle: import("react").NamedExoticComponent<import("styled-components").ExecutionProps & {
4
+ customMixins?: ColorThemeType | undefined;
5
+ forceTheme?: ThemeType | undefined;
6
+ }>;
7
+ //# sourceMappingURL=styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/provider/styles.ts"],"names":[],"mappings":";AAKA,OAAO,EAAY,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAEzE,eAAO,MAAM,cAAc;;;EAa1B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remember-web/mixin",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "RUI Mixin",
5
5
  "homepage": "https://dramancompany.github.io/rui/",
6
6
  "author": "Remember",
@@ -41,6 +41,7 @@
41
41
  "@babel/core": "^7.20.12",
42
42
  "@babel/plugin-transform-runtime": "^7.19.6",
43
43
  "@babel/preset-env": "^7.22.9",
44
+ "@babel/preset-react": "^7.24.1",
44
45
  "@babel/preset-typescript": "^7.22.5",
45
46
  "@remember-web/shared": "workspace:^",
46
47
  "@rollup/plugin-babel": "^6.0.4",
@@ -48,6 +49,7 @@
48
49
  "@rollup/plugin-node-resolve": "^15.0.1",
49
50
  "@rollup/plugin-terser": "^0.4.0",
50
51
  "eslint-config-rui": "workspace:*",
52
+ "react": "^18.2.0",
51
53
  "rollup": "^4.13.0",
52
54
  "rollup-plugin-copy": "^3.4.0",
53
55
  "rollup-plugin-delete": "^2.0.0",
@@ -62,6 +64,7 @@
62
64
  "typescript": "^5.4.3"
63
65
  },
64
66
  "peerDependencies": {
67
+ "react": "^18.2.0",
65
68
  "styled-components": ">=6"
66
69
  }
67
70
  }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './colors';
2
2
  export * from './mediaQuery';
3
3
  export * from './typography';
4
+ // export * from './provider';
@@ -0,0 +1,54 @@
1
+ 'use client';
2
+
3
+ import type { ReactNode } from 'react';
4
+ import { createContext, useContext, useMemo } from 'react';
5
+
6
+ import type { ColorThemeType, ThemeType } from '@/colors';
7
+ import { getBrowserTheme } from '@/colors';
8
+
9
+ import { RUIGlobalStyle } from './styles';
10
+
11
+ export interface RUIContentProps {
12
+ customMixins?: ColorThemeType;
13
+ forceTheme?: ThemeType;
14
+ setTheme?: (theme: ThemeType) => void;
15
+ }
16
+
17
+ export interface RUIContextValue {
18
+ currentTheme: ThemeType;
19
+ setTheme: RUIContentProps['setTheme'];
20
+ }
21
+
22
+ const RUIContext = createContext<RUIContextValue | null>(null);
23
+
24
+ /** theme과 setTheme은 사용하는 곳에서 주입,
25
+ * 기본적으로는 브라우저의 미디어쿼리를 통해서 light, dark를 결정 */
26
+ export function RUIProvider({
27
+ children,
28
+ customMixins,
29
+ forceTheme,
30
+ setTheme,
31
+ }: { children: ReactNode } & RUIContentProps) {
32
+ const currentTheme: ThemeType = forceTheme ?? getBrowserTheme();
33
+ const ruiContextValue: RUIContextValue = useMemo(
34
+ () => ({ currentTheme, setTheme }),
35
+ [currentTheme, setTheme]
36
+ );
37
+
38
+ return (
39
+ <RUIContext.Provider value={ruiContextValue}>
40
+ <RUIGlobalStyle customMixins={customMixins} forceTheme={forceTheme} />
41
+ {children}
42
+ </RUIContext.Provider>
43
+ );
44
+ }
45
+
46
+ export function useRUI() {
47
+ const ruiContextValue = useContext(RUIContext);
48
+
49
+ if (ruiContextValue === null) {
50
+ throw new Error('useRUI must be used within RUIProvider');
51
+ }
52
+
53
+ return ruiContextValue;
54
+ }
@@ -0,0 +1,36 @@
1
+ 'use client';
2
+
3
+ import { createGlobalStyle, css } from 'styled-components';
4
+
5
+ import { RUI_COLOR_THEME } from '@/colors/theme';
6
+ import { hexToRgb, type ColorThemeType, type ThemeType } from '@/colors';
7
+
8
+ export const RUIGlobalStyle = createGlobalStyle<{
9
+ customMixins?: ColorThemeType;
10
+ forceTheme?: ThemeType;
11
+ }>(
12
+ ({ customMixins, forceTheme }) => css`
13
+ :root {
14
+ ${getThemeCssFragment({ theme: forceTheme || 'light', customMixins })};
15
+
16
+ @media (prefers-color-scheme: dark) {
17
+ ${getThemeCssFragment({ theme: forceTheme || 'dark', customMixins })}
18
+ }
19
+ }
20
+ `
21
+ );
22
+
23
+ function getThemeCssFragment({
24
+ theme,
25
+ customMixins,
26
+ }: {
27
+ theme: ThemeType;
28
+ customMixins?: ColorThemeType;
29
+ }) {
30
+ return Object.entries({
31
+ ...RUI_COLOR_THEME[theme],
32
+ ...customMixins?.[theme],
33
+ }).map(
34
+ ([key, value]) => `${key}: ${value}; ${key}__rgb: ${hexToRgb(value)};`
35
+ );
36
+ }