Skip to content
This repository was archived by the owner on Dec 6, 2021. It is now read-only.

Commit c40d5a8

Browse files
committed
fix(flex): flex style not working, #7
1 parent 1dff28f commit c40d5a8

File tree

2 files changed

+22
-75
lines changed

2 files changed

+22
-75
lines changed

src/components/flex/index.ts

+10-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { h, defineComponent, computed, mergeProps, PropType } from "vue"
2-
import _forEach from 'lodash/forEach'
32
import { View } from '@tarojs/components'
43
import { AtFlexProps } from 'types/flex'
54

@@ -9,52 +8,36 @@ const AtFlex = defineComponent({
98
props: {
109
wrap: {
1110
type: String as PropType<AtFlexProps['wrap']>,
12-
default: 'no-wrap',
1311
},
1412
align: {
1513
type: String as PropType<AtFlexProps['align']>,
16-
default: 'stretch',
1714
},
1815
justify: {
1916
type: String as PropType<AtFlexProps['justify']>,
20-
default: 'start',
2117
},
2218
direction: {
2319
type: String as PropType<AtFlexProps['direction']>,
24-
default: 'row',
2520
},
2621
alignContent: {
2722
type: String as PropType<AtFlexProps['alignContent']>,
28-
default: 'center'
2923
},
3024
},
3125

3226
setup(props: AtFlexProps, { attrs, slots }) {
3327

34-
const rootClass = computed(() => {
35-
const root = { 'at-row': true }
36-
37-
_forEach(props, (value, key) => {
38-
switch (key) {
39-
case 'wrap':
40-
root[`at-row--${value}`] = true
41-
return
42-
case 'alignContent':
43-
root[`at-row__align-content--${value}`] = true
44-
return
45-
default:
46-
root[`at-row__${key}--${value}`] = true
47-
return
48-
}
49-
})
50-
51-
return root
52-
})
28+
const rootClasses = computed(() => ({
29+
'at-row': true,
30+
[`at-row--${props.wrap}`]: Boolean(props.wrap),
31+
[`at-row__align--${props.align}`]: Boolean(props.align),
32+
[`at-row__justify--${props.justify}`]: Boolean(props.justify),
33+
[`at-row__direction--${props.direction}`]: Boolean(props.direction),
34+
[`at-row__align-content--${props.alignContent}`]: Boolean(props.alignContent)
35+
}))
5336

5437
return () => (
5538
h(View, mergeProps(attrs, {
56-
class: rootClass.value
57-
}), { default: () => slots.default && slots.default() })
39+
class: rootClasses.value
40+
}), { default: () => slots.default?.() })
5841
)
5942
}
6043
})

src/components/flex/item/index.ts

+12-48
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
import { h, defineComponent, computed, mergeProps, PropType } from "vue"
2-
import _forEach from 'lodash/forEach'
32
import { View } from '@tarojs/components'
43
import { AtFlexItemProps } from 'types/flex'
54

65
const AtFlexItem = defineComponent({
76
name: "AtFlexItem",
87

98
props: {
10-
isAuto: {
11-
type: Boolean,
12-
default: false,
13-
},
14-
isWrap: {
15-
type: Boolean,
16-
default: false,
17-
},
9+
isAuto: Boolean,
10+
isWrap: Boolean,
1811
align: {
1912
type: String as PropType<AtFlexItemProps['align']>,
2013
default: 'center',
@@ -31,48 +24,19 @@ const AtFlexItem = defineComponent({
3124

3225
setup(props: AtFlexItemProps, { attrs, slots }) {
3326

34-
const rootClass = computed(() => {
35-
const root = { 'at-col': true }
36-
37-
_forEach(props, (value, key) => {
38-
switch (key) {
39-
case 'isAuto':
40-
if (value) {
41-
root['at-col--auto'] = true
42-
return
43-
}
44-
return
45-
case 'isWrap':
46-
if (value) {
47-
root[`at-col--wrap`] = true
48-
return
49-
}
50-
return
51-
case 'size':
52-
if (value) {
53-
root[`at-col-${value}`] = true
54-
return
55-
}
56-
return
57-
case 'offset':
58-
if (value != 0) {
59-
root[`at-col__offset-${value}`] = true
60-
return
61-
}
62-
return
63-
default:
64-
root[`at-col__${key}--${value}`] = true
65-
return
66-
}
67-
})
68-
69-
return root
70-
})
27+
const rootClasses = computed(() => ({
28+
[`at-col-${props.size}`]: Boolean(props.size),
29+
[`at-col__align--${props.align}`]: Boolean(props.align),
30+
[`at-col__offset-${props.offset}`]: Boolean(props.offset),
31+
'at-col--auto': Boolean(props.isAuto),
32+
'at-col--wrap': Boolean(props.isWrap),
33+
'at-col': true,
34+
}))
7135

7236
return () => (
7337
h(View, mergeProps(attrs, {
74-
class: rootClass.value
75-
}), { default: () => slots.default && slots.default() })
38+
class: rootClasses.value
39+
}), { default: () => slots.default?.() })
7640
)
7741
}
7842
})

0 commit comments

Comments
 (0)