-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(grid): move to script setup (#3037)
- Loading branch information
Showing
19 changed files
with
350 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<template> | ||
<view :class="rootClass" :style="rootStyle"> | ||
<slot></slot> | ||
</view> | ||
</template> | ||
<script setup lang="ts"> | ||
import { pxCheck, useChildren } from '@/packages/utils' | ||
import { GRID_KEY, type GridDirection } from './types' | ||
import { computed, type CSSProperties } from 'vue' | ||
defineOptions({ | ||
name: 'NutGrid' | ||
}) | ||
export type GridProps = Partial<{ | ||
columnNum: string | number | ||
border: boolean | ||
gutter: string | number | ||
center: boolean | ||
square: boolean | ||
reverse: boolean | ||
direction: GridDirection | ||
clickable: boolean | ||
}> | ||
const props = withDefaults(defineProps<GridProps>(), { | ||
columnNum: 4, | ||
border: true, | ||
gutter: 0, | ||
center: true, | ||
square: false, | ||
reverse: false, | ||
clickable: false | ||
}) | ||
const { linkChildren } = useChildren(GRID_KEY) | ||
linkChildren({ props }) | ||
const rootClass = computed(() => { | ||
const prefixCls = 'nut-grid' | ||
return { | ||
[prefixCls]: true, | ||
[`${prefixCls}--border`]: props.border && !props.gutter | ||
} | ||
}) | ||
const rootStyle = computed(() => { | ||
const style: CSSProperties = {} | ||
if (props.gutter) { | ||
style.paddingLeft = pxCheck(props.gutter) | ||
} | ||
return style | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<template> | ||
<view :class="rootClass" :style="rootStyle"> | ||
<slot></slot> | ||
</view> | ||
</template> | ||
<script setup lang="ts"> | ||
import { pxCheck, useChildren } from '@/packages/utils' | ||
import { GRID_KEY, type GridDirection } from './types' | ||
import { computed, type CSSProperties } from 'vue' | ||
defineOptions({ | ||
name: 'NutGrid' | ||
}) | ||
export type GridProps = Partial<{ | ||
columnNum: string | number | ||
border: boolean | ||
gutter: string | number | ||
center: boolean | ||
square: boolean | ||
reverse: boolean | ||
direction: GridDirection | ||
clickable: boolean | ||
}> | ||
const props = withDefaults(defineProps<GridProps>(), { | ||
columnNum: 4, | ||
border: true, | ||
gutter: 0, | ||
center: true, | ||
square: false, | ||
reverse: false, | ||
clickable: false | ||
}) | ||
const { linkChildren } = useChildren(GRID_KEY) | ||
linkChildren({ props }) | ||
const rootClass = computed(() => { | ||
const prefixCls = 'nut-grid' | ||
return { | ||
[prefixCls]: true, | ||
[`${prefixCls}--border`]: props.border && !props.gutter | ||
} | ||
}) | ||
const rootStyle = computed(() => { | ||
const style: CSSProperties = {} | ||
if (props.gutter) { | ||
style.paddingLeft = pxCheck(props.gutter) | ||
} | ||
return style | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Grid from './grid.taro.vue' | ||
import type { ComponentPublicInstance } from 'vue' | ||
import { withInstall } from '@/packages/utils' | ||
|
||
withInstall(Grid) | ||
|
||
export type { GridProps } from './grid.taro.vue' | ||
|
||
export type { GridDirection } from './types' | ||
|
||
export type GridInstance = ComponentPublicInstance & InstanceType<typeof Grid> | ||
|
||
export { Grid, Grid as default } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Grid from './grid.vue' | ||
import type { ComponentPublicInstance } from 'vue' | ||
import { withInstall } from '@/packages/utils' | ||
|
||
withInstall(Grid) | ||
|
||
export type { GridProps } from './grid.vue' | ||
|
||
export type { GridDirection } from './types' | ||
|
||
export type GridInstance = ComponentPublicInstance & InstanceType<typeof Grid> | ||
|
||
export { Grid, Grid as default } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const GRID_KEY = Symbol('grid') | ||
export type GridDirection = 'horizontal' | 'vertical' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<template> | ||
<view class="nut-grid-item" :style="rootStyle" @click="handleClick"> | ||
<view :class="contentClass"> | ||
<slot></slot> | ||
<view class="nut-grid-item__text"> | ||
<template v-if="text">{{ text }}</template> | ||
<slot v-else name="text"></slot> | ||
</view> | ||
</view> | ||
</view> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed, CSSProperties } from 'vue' | ||
import { pxCheck, useParent } from '@/packages/utils' | ||
import { GRID_KEY } from '../grid/types' | ||
defineOptions({ | ||
name: 'NutGridItem' | ||
}) | ||
export type GridItemProps = Partial<{ | ||
text: string | ||
}> | ||
withDefaults(defineProps<GridItemProps>(), {}) | ||
const emit = defineEmits(['click']) | ||
const { parent: parentObj, index } = useParent(GRID_KEY) | ||
const parent = parentObj?.props || {} | ||
const rootStyle = computed(() => { | ||
const style: CSSProperties = { | ||
flexBasis: `${100 / +parent.columnNum}%` | ||
} | ||
if (parent.square) { | ||
style.paddingTop = `${100 / +parent.columnNum}%` | ||
} else if (parent.gutter) { | ||
style.paddingRight = pxCheck(parent.gutter) | ||
if (index.value >= +parent.columnNum) { | ||
style.marginTop = pxCheck(parent.gutter) | ||
} | ||
} | ||
return style | ||
}) | ||
const contentClass = computed(() => { | ||
const prefixCls = `nut-grid-item__content` | ||
return { | ||
[`${prefixCls}`]: true, | ||
[`${prefixCls}--border`]: parent.border, | ||
[`${prefixCls}--surround`]: parent.border && parent.gutter, | ||
[`${prefixCls}--center`]: parent.center, | ||
[`${prefixCls}--square`]: parent.square, | ||
[`${prefixCls}--reverse`]: parent.reverse, | ||
[`${prefixCls}--${parent.direction}`]: !!parent.direction, | ||
[`${prefixCls}--clickable`]: parent.clickable | ||
} | ||
}) | ||
const handleClick = (event: Event) => { | ||
emit('click', event) | ||
} | ||
</script> |
Oops, something went wrong.