Skip to content

Commit f2e3ace

Browse files
authored
Merge pull request #46 from dev-five-git/css-selector-grid
Implement Grid
2 parents 1b78979 + 76e8fa1 commit f2e3ace

File tree

8 files changed

+75
-1
lines changed

8 files changed

+75
-1
lines changed

.changeset/breezy-owls-change.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+
Add grid, Support for selector in css

libs/extractor/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,24 @@ mod tests {
812812
<Box className={c({
813813
bg:"red"
814814
})}/>;
815+
"#,
816+
ExtractOption {
817+
package: "@devup-ui/core".to_string(),
818+
css_file: None
819+
}
820+
)
821+
.unwrap());
822+
823+
reset_class_map();
824+
assert_debug_snapshot!(extract(
825+
"test.tsx",
826+
r#"import { css } from "@devup-ui/core";
827+
<Box className={css({
828+
_hover: {
829+
bg:"red",
830+
color:"blue"
831+
}
832+
})}/>;
815833
"#,
816834
ExtractOption {
817835
package: "@devup-ui/core".to_string(),
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "extract(\"test.tsx\",\nr#\"import { css } from \"@devup-ui/core\";\n<Box className={css({\n _hover: {\n bg:\"red\",\n color:\"blue\"\n }\n})}/>;\n\"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap()"
4+
---
5+
ExtractOutput {
6+
styles: [
7+
Static(
8+
ExtractStaticStyle {
9+
property: "color",
10+
value: "blue",
11+
level: 0,
12+
selector: Some(
13+
Postfix(
14+
"hover",
15+
),
16+
),
17+
basic: false,
18+
},
19+
),
20+
Static(
21+
ExtractStaticStyle {
22+
property: "background",
23+
value: "red",
24+
level: 0,
25+
selector: Some(
26+
Postfix(
27+
"hover",
28+
),
29+
),
30+
basic: false,
31+
},
32+
),
33+
],
34+
code: "import \"@devup-ui/core/devup-ui.css\";\nimport { css } from \"@devup-ui/core\";\n<Box className={css(\"d0 d1\")} />;\n",
35+
}

packages/react/src/__tests__/index.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('export', () => {
1010
Text: expect.any(Function),
1111
VStack: expect.any(Function),
1212
Image: expect.any(Function),
13+
Grid: expect.any(Function),
1314

1415
css: expect.any(Function),
1516
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { DevupProps } from '../types/props'
2+
import type { Merge } from '../types/utils'
3+
4+
export function Grid<T extends React.ElementType = 'div'>(
5+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
6+
props: Merge<React.ComponentProps<T>, DevupProps>,
7+
): React.ReactElement {
8+
throw new Error('Cannot run on the runtime')
9+
}

packages/react/src/components/__tests__/index.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Box } from '../Box'
22
import { Button } from '../Button'
33
import { Center } from '../Center'
44
import { Flex } from '../Flex'
5+
import { Grid } from '../Grid'
56
import { Image } from '../Image'
67
import { Input } from '../Input'
78
import { Text } from '../Text'
@@ -17,5 +18,6 @@ describe('Component', () => {
1718
expect(() => Text({})).toThrowError('Cannot run on the runtime')
1819
expect(() => VStack({})).toThrowError('Cannot run on the runtime')
1920
expect(() => Image({})).toThrowError('Cannot run on the runtime')
21+
expect(() => Grid({})).toThrowError('Cannot run on the runtime')
2022
})
2123
})

packages/react/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export { Box } from './components/Box'
22
export { Button } from './components/Button'
33
export { Center } from './components/Center'
44
export { Flex } from './components/Flex'
5+
export { Grid } from './components/Grid'
56
export { Image } from './components/Image'
67
export { Input } from './components/Input'
78
export { Text } from './components/Text'

packages/react/src/utils/css.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { DevupCommonProps } from '../types/props'
2+
import type { DevupSelectorProps } from '../types/props/selector'
23

34
export function css(props: DevupCommonProps): string
45
export function css(strings: TemplateStringsArray): string
56

6-
export function css(strings: TemplateStringsArray | DevupCommonProps): string {
7+
export function css(
8+
strings: TemplateStringsArray | (DevupCommonProps & DevupSelectorProps),
9+
): string {
710
if (Array.isArray(strings)) {
811
return strings.join('')
912
}

0 commit comments

Comments
 (0)