-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor(grid): use tsx fix #1409 * test(grid): update grid test cases * test(grid): update grid test cases * test(grid): update grid test cases * refactor(grid): update props name
- Loading branch information
Showing
5 changed files
with
93 additions
and
126 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 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,73 @@ | ||
import { defineComponent, getCurrentInstance, computed, inject } from 'vue'; | ||
import isObject from 'lodash/isObject'; | ||
import isString from 'lodash/isString'; | ||
import isFunction from 'lodash/isFunction'; | ||
|
||
import config from '../config'; | ||
import props from './grid-item-props'; | ||
import { useTNodeJSX } from '../hooks/tnode'; | ||
import TImage from '../image'; | ||
import TBadge from '../badge'; | ||
|
||
const { prefix } = config; | ||
const name = `${prefix}-grid-item`; | ||
|
||
export default defineComponent({ | ||
name, | ||
components: { TImage, TBadge }, | ||
props, | ||
setup(props, context) { | ||
const renderTNodeJSX = useTNodeJSX(); | ||
const { column, border, align, gutter } = inject<any>('grid'); | ||
|
||
const rootStyle = computed(() => { | ||
const percent = column.value > 0 ? `${100 / +column.value}%` : 0; | ||
const style: Record<string, any> = { | ||
textAlign: ['center', 'left'].includes(align.value) ? align.value : 'center', | ||
}; | ||
if (percent !== 0) { | ||
style.flexBasis = percent; | ||
} | ||
return style; | ||
}); | ||
|
||
const size = computed(() => { | ||
if (column.value > 4 || !column.value) return 'small'; | ||
return column.value < 4 ? 'large' : 'middle'; | ||
}); | ||
|
||
const realImage = computed(() => { | ||
if (isString(props.image)) return { src: props.image }; | ||
if (isObject(props.image) && !isFunction(props.image) && !context.slots.image) { | ||
return props.image; | ||
} | ||
return null; | ||
}); | ||
|
||
const gridItemClasses = computed(() => [ | ||
`${name}`, | ||
`${name}--${props.layout}`, | ||
{ [`${name}--bordered`]: border.value, [`${name}--surround`]: border.value && gutter.value }, | ||
]); | ||
|
||
return () => { | ||
const renderImage = () => | ||
realImage.value ? <t-image shape="round" {...realImage.value} /> : renderTNodeJSX('image'); | ||
|
||
return ( | ||
<div class={gridItemClasses.value} style={rootStyle.value}> | ||
<div class={`${name}__image ${name}__image--${size.value}`}> | ||
{props.badge ? <t-badge {...(props.badge as Object)}>{renderImage()}</t-badge> : renderImage()} | ||
</div> | ||
|
||
<div class={`${name}__content ${name}__content--${props.layout}`}> | ||
<div class={`${name}__title ${name}__title--${size.value}`}>{renderTNodeJSX('text')}</div> | ||
<div class={`${name}__description ${name}__description--${props.layout}`}> | ||
{renderTNodeJSX('description')} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
}, | ||
}); |
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