Skip to content

Commit 74f7c0d

Browse files
authored
Merge pull request #28 from dev-five-git/fix-type
Fix type issue
2 parents fe6e3fd + 0040445 commit 74f7c0d

File tree

8 files changed

+36
-23
lines changed

8 files changed

+36
-23
lines changed

.changeset/beige-cups-count.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/wasm": patch
3+
---
4+
5+
Optimize str argument

.changeset/green-mails-press.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/react": patch
3+
---
4+
5+
Fix selector type

bindings/devup-ui-wasm/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl Output {
6969
}
7070
}
7171
ExtractStyleValue::Css(cs) => {
72-
if sheet.add_css(cls, cs.css.clone()) {
72+
if sheet.add_css(&cls, &cs.css) {
7373
collected = true;
7474
}
7575
}
@@ -156,15 +156,15 @@ fn theme_object_to_hashmap(js_value: JsValue) -> Result<Theme, JsValue> {
156156
if let (Some(var_key_str), Some(var_value_str)) =
157157
(var_key.as_string(), var_value.as_string())
158158
{
159-
color_theme.add_color(var_key_str, var_value_str);
159+
color_theme.add_color(&var_key_str, &var_value_str);
160160
} else {
161161
return Err(JsValue::from_str(
162162
"Failed to get key and value from the theme object",
163163
));
164164
}
165165
}
166166
}
167-
theme.colors.add_theme(key_str, color_theme);
167+
theme.colors.add_theme(&key_str, color_theme);
168168
}
169169
}
170170
}

libs/sheet/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@ impl StyleSheet {
112112
self.properties.entry(level).or_default().insert(prop)
113113
}
114114

115-
pub fn add_css(&mut self, class_name: String, css: String) -> bool {
116-
let prop = StyleSheetCss { class_name, css };
115+
pub fn add_css(&mut self, class_name: &str, css: &str) -> bool {
116+
let prop = StyleSheetCss {
117+
class_name: class_name.to_string(),
118+
css: css.to_string(),
119+
};
117120
self.css.insert(prop)
118121
}
119122

@@ -264,7 +267,7 @@ mod tests {
264267
assert_debug_snapshot!(sheet.create_css());
265268

266269
let mut sheet = StyleSheet::new();
267-
sheet.add_css("test".to_string(), "display:flex;".to_string());
270+
sheet.add_css("test", "display:flex;");
268271
sheet.set_theme(Theme::new());
269272
assert_debug_snapshot!(sheet.create_css());
270273
}

libs/sheet/src/theme.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ impl ColorTheme {
1717
}
1818
}
1919

20-
pub fn add_color(&mut self, name: String, value: String) {
21-
self.data.insert(name, value);
20+
pub fn add_color(&mut self, name: &str, value: &str) {
21+
self.data.insert(name.to_string(), value.to_string());
2222
}
2323

2424
pub fn get_color(&self, name: &str) -> Option<&String> {
@@ -54,8 +54,8 @@ impl Color {
5454
}
5555
}
5656

57-
pub fn add_theme(&mut self, name: String, theme: ColorTheme) {
58-
self.themes.insert(name, theme);
57+
pub fn add_theme(&mut self, name: &str, theme: ColorTheme) {
58+
self.themes.insert(name.to_string(), theme);
5959
}
6060

6161
pub fn get_theme(&self, name: &str) -> Option<&ColorTheme> {
@@ -156,12 +156,12 @@ impl Theme {
156156
}
157157
}
158158

159-
pub fn add_color_theme(&mut self, name: String, theme: ColorTheme) {
159+
pub fn add_color_theme(&mut self, name: &str, theme: ColorTheme) {
160160
self.colors.add_theme(name, theme);
161161
}
162162

163-
pub fn add_typography(&mut self, name: String, typography: Vec<Typography>) {
164-
self.typography.insert(name, typography);
163+
pub fn add_typography(&mut self, name: &str, typography: Vec<Typography>) {
164+
self.typography.insert(name.to_string(), typography);
165165
}
166166

167167
pub fn to_css(&self) -> String {
@@ -233,13 +233,13 @@ mod tests {
233233
fn to_css_from_theme() {
234234
let mut theme = Theme::new();
235235
let mut color_theme = ColorTheme::new();
236-
color_theme.add_color("primary".to_string(), "#000".to_string());
237-
theme.add_color_theme("default".to_string(), color_theme);
236+
color_theme.add_color("primary", "#000");
237+
theme.add_color_theme("default", color_theme);
238238
let mut color_theme = ColorTheme::new();
239-
color_theme.add_color("primary".to_string(), "#fff".to_string());
240-
theme.add_color_theme("dark".to_string(), color_theme);
239+
color_theme.add_color("primary", "#fff");
240+
theme.add_color_theme("dark", color_theme);
241241
theme.add_typography(
242-
"default".to_string(),
242+
"default",
243243
vec![
244244
Typography::new(
245245
Some("Arial".to_string()),
@@ -261,7 +261,7 @@ mod tests {
261261
);
262262

263263
theme.add_typography(
264-
"default1".to_string(),
264+
"default1",
265265
vec![Typography::new(
266266
Some("Arial".to_string()),
267267
Some("24px".to_string()),

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "module",
55
"scripts": {
66
"lint": "eslint",
7-
"build": "vite build"
7+
"build": "tsc && vite build"
88
},
99
"publishConfig": {
1010
"access": "public"

packages/react/src/types/props/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import type { DevupUiImageProps } from './image'
1616
import type { DevupUiInlineProps } from './inline'
1717
import type { DevupUiListProps } from './list'
1818
import type { DevupUiMaskingProps } from './masking'
19-
import type { DevupMediaProps } from './media'
2019
import type { DevupUiMotionPathProps } from './motion-path'
2120
import type { DevupUiOverflowProps } from './overflow'
2221
import type { DevupUiOverflowBehaviorProps } from './overflow-behavior'
2322
import type { DevupUiPositionProps } from './position'
2423
import type { DevupUiScrollbarProps } from './scrollbar'
24+
import type { DevupSelectorProps } from './selector'
2525
import type { DevupUiShapeProps } from './shape'
2626
import type { DevupUiTableProps } from './table'
2727
import type { DevupUiTextProps } from './text'
@@ -61,7 +61,7 @@ export interface DevupCommonProps
6161
DevupUiUiProps,
6262
DevupUiViewTransitionProps {}
6363

64-
export interface DevupProps extends DevupCommonProps, DevupMediaProps {
64+
export interface DevupProps extends DevupCommonProps, DevupSelectorProps {
6565
as?: React.ElementType
6666
}
6767

packages/react/src/types/props/selector/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { DevupCommonProps } from '../index'
22

3-
export interface DevupMediaProps {
3+
export interface DevupSelectorProps {
44
_active?: DevupCommonProps
55
_checked?: DevupCommonProps
66
_default?: DevupCommonProps

0 commit comments

Comments
 (0)