From 004044565b1e60a5ffa55a9da7ca9cceeae7c15b Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Mon, 20 Jan 2025 10:18:31 +0900 Subject: [PATCH] Fix type issue Optimize argument --- .changeset/beige-cups-count.md | 5 ++++ .changeset/green-mails-press.md | 5 ++++ bindings/devup-ui-wasm/src/lib.rs | 6 ++--- libs/sheet/src/lib.rs | 9 ++++--- libs/sheet/src/theme.rs | 26 +++++++++---------- packages/react/package.json | 2 +- packages/react/src/types/props/index.ts | 4 +-- .../react/src/types/props/selector/index.ts | 2 +- 8 files changed, 36 insertions(+), 23 deletions(-) create mode 100644 .changeset/beige-cups-count.md create mode 100644 .changeset/green-mails-press.md diff --git a/.changeset/beige-cups-count.md b/.changeset/beige-cups-count.md new file mode 100644 index 00000000..0c491d0f --- /dev/null +++ b/.changeset/beige-cups-count.md @@ -0,0 +1,5 @@ +--- +"@devup-ui/wasm": patch +--- + +Optimize str argument diff --git a/.changeset/green-mails-press.md b/.changeset/green-mails-press.md new file mode 100644 index 00000000..cf195c86 --- /dev/null +++ b/.changeset/green-mails-press.md @@ -0,0 +1,5 @@ +--- +"@devup-ui/react": patch +--- + +Fix selector type diff --git a/bindings/devup-ui-wasm/src/lib.rs b/bindings/devup-ui-wasm/src/lib.rs index 7b4d4776..88c0df51 100644 --- a/bindings/devup-ui-wasm/src/lib.rs +++ b/bindings/devup-ui-wasm/src/lib.rs @@ -69,7 +69,7 @@ impl Output { } } ExtractStyleValue::Css(cs) => { - if sheet.add_css(cls, cs.css.clone()) { + if sheet.add_css(&cls, &cs.css) { collected = true; } } @@ -156,7 +156,7 @@ fn theme_object_to_hashmap(js_value: JsValue) -> Result { if let (Some(var_key_str), Some(var_value_str)) = (var_key.as_string(), var_value.as_string()) { - color_theme.add_color(var_key_str, var_value_str); + color_theme.add_color(&var_key_str, &var_value_str); } else { return Err(JsValue::from_str( "Failed to get key and value from the theme object", @@ -164,7 +164,7 @@ fn theme_object_to_hashmap(js_value: JsValue) -> Result { } } } - theme.colors.add_theme(key_str, color_theme); + theme.colors.add_theme(&key_str, color_theme); } } } diff --git a/libs/sheet/src/lib.rs b/libs/sheet/src/lib.rs index b41f8a88..9d22f368 100644 --- a/libs/sheet/src/lib.rs +++ b/libs/sheet/src/lib.rs @@ -112,8 +112,11 @@ impl StyleSheet { self.properties.entry(level).or_default().insert(prop) } - pub fn add_css(&mut self, class_name: String, css: String) -> bool { - let prop = StyleSheetCss { class_name, css }; + pub fn add_css(&mut self, class_name: &str, css: &str) -> bool { + let prop = StyleSheetCss { + class_name: class_name.to_string(), + css: css.to_string(), + }; self.css.insert(prop) } @@ -264,7 +267,7 @@ mod tests { assert_debug_snapshot!(sheet.create_css()); let mut sheet = StyleSheet::new(); - sheet.add_css("test".to_string(), "display:flex;".to_string()); + sheet.add_css("test", "display:flex;"); sheet.set_theme(Theme::new()); assert_debug_snapshot!(sheet.create_css()); } diff --git a/libs/sheet/src/theme.rs b/libs/sheet/src/theme.rs index 5dd094aa..c6042ea7 100644 --- a/libs/sheet/src/theme.rs +++ b/libs/sheet/src/theme.rs @@ -17,8 +17,8 @@ impl ColorTheme { } } - pub fn add_color(&mut self, name: String, value: String) { - self.data.insert(name, value); + pub fn add_color(&mut self, name: &str, value: &str) { + self.data.insert(name.to_string(), value.to_string()); } pub fn get_color(&self, name: &str) -> Option<&String> { @@ -54,8 +54,8 @@ impl Color { } } - pub fn add_theme(&mut self, name: String, theme: ColorTheme) { - self.themes.insert(name, theme); + pub fn add_theme(&mut self, name: &str, theme: ColorTheme) { + self.themes.insert(name.to_string(), theme); } pub fn get_theme(&self, name: &str) -> Option<&ColorTheme> { @@ -156,12 +156,12 @@ impl Theme { } } - pub fn add_color_theme(&mut self, name: String, theme: ColorTheme) { + pub fn add_color_theme(&mut self, name: &str, theme: ColorTheme) { self.colors.add_theme(name, theme); } - pub fn add_typography(&mut self, name: String, typography: Vec) { - self.typography.insert(name, typography); + pub fn add_typography(&mut self, name: &str, typography: Vec) { + self.typography.insert(name.to_string(), typography); } pub fn to_css(&self) -> String { @@ -233,13 +233,13 @@ mod tests { fn to_css_from_theme() { let mut theme = Theme::new(); let mut color_theme = ColorTheme::new(); - color_theme.add_color("primary".to_string(), "#000".to_string()); - theme.add_color_theme("default".to_string(), color_theme); + color_theme.add_color("primary", "#000"); + theme.add_color_theme("default", color_theme); let mut color_theme = ColorTheme::new(); - color_theme.add_color("primary".to_string(), "#fff".to_string()); - theme.add_color_theme("dark".to_string(), color_theme); + color_theme.add_color("primary", "#fff"); + theme.add_color_theme("dark", color_theme); theme.add_typography( - "default".to_string(), + "default", vec![ Typography::new( Some("Arial".to_string()), @@ -261,7 +261,7 @@ mod tests { ); theme.add_typography( - "default1".to_string(), + "default1", vec![Typography::new( Some("Arial".to_string()), Some("24px".to_string()), diff --git a/packages/react/package.json b/packages/react/package.json index 80d2f64d..740c80ce 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -4,7 +4,7 @@ "type": "module", "scripts": { "lint": "eslint", - "build": "vite build" + "build": "tsc && vite build" }, "publishConfig": { "access": "public" diff --git a/packages/react/src/types/props/index.ts b/packages/react/src/types/props/index.ts index 2cd7c251..60dde67f 100644 --- a/packages/react/src/types/props/index.ts +++ b/packages/react/src/types/props/index.ts @@ -16,12 +16,12 @@ import type { DevupUiImageProps } from './image' import type { DevupUiInlineProps } from './inline' import type { DevupUiListProps } from './list' import type { DevupUiMaskingProps } from './masking' -import type { DevupMediaProps } from './media' import type { DevupUiMotionPathProps } from './motion-path' import type { DevupUiOverflowProps } from './overflow' import type { DevupUiOverflowBehaviorProps } from './overflow-behavior' import type { DevupUiPositionProps } from './position' import type { DevupUiScrollbarProps } from './scrollbar' +import type { DevupSelectorProps } from './selector' import type { DevupUiShapeProps } from './shape' import type { DevupUiTableProps } from './table' import type { DevupUiTextProps } from './text' @@ -61,7 +61,7 @@ export interface DevupCommonProps DevupUiUiProps, DevupUiViewTransitionProps {} -export interface DevupProps extends DevupCommonProps, DevupMediaProps { +export interface DevupProps extends DevupCommonProps, DevupSelectorProps { as?: React.ElementType } diff --git a/packages/react/src/types/props/selector/index.ts b/packages/react/src/types/props/selector/index.ts index 2eafe383..99ff6091 100644 --- a/packages/react/src/types/props/selector/index.ts +++ b/packages/react/src/types/props/selector/index.ts @@ -1,6 +1,6 @@ import type { DevupCommonProps } from '../index' -export interface DevupMediaProps { +export interface DevupSelectorProps { _active?: DevupCommonProps _checked?: DevupCommonProps _default?: DevupCommonProps