-
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.
- Loading branch information
Showing
8 changed files
with
436 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<template> | ||
<view class="nut-cell-group"> | ||
<slot v-if="$slots.title" name="title"></slot> | ||
<view v-else-if="title" class="nut-cell-group__title">{{ title }}</view> | ||
<slot v-if="$slots.desc" name="desc"></slot> | ||
<view v-else-if="desc" class="nut-cell-group__desc">{{ desc }}</view> | ||
<view class="nut-cell-group__wrap"> | ||
<slot></slot> | ||
</view> | ||
</view> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { createComponent } from '@/packages/utils/create'; | ||
const { create } = createComponent('cell-group'); | ||
export default create({ | ||
props: { | ||
title: { type: String, default: '' }, | ||
desc: { type: String, default: '' } | ||
} | ||
}); | ||
</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,95 @@ | ||
<script lang="ts"> | ||
import { h, watch, provide, computed, ComponentInternalInstance, reactive, ComponentPublicInstance } from 'vue'; | ||
import { createComponent } from '@/packages/utils/create'; | ||
import { useExpose } from '@/packages/utils/useExpose/index'; | ||
const { create, componentName } = createComponent('checkbox-group'); | ||
export default create({ | ||
props: { | ||
modelValue: { | ||
type: Array, | ||
default: () => [] | ||
}, | ||
disabled: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
max: { | ||
type: Number, | ||
default: 0 | ||
} | ||
}, | ||
emits: ['change', 'update:modelValue'], | ||
setup(props, { slots, emit }) { | ||
const state = reactive({ | ||
children: [] as ComponentPublicInstance[] | ||
}); | ||
const link = (child: ComponentInternalInstance) => { | ||
child.proxy && state.children.push(child.proxy); | ||
}; | ||
const unlink = (child: ComponentInternalInstance) => { | ||
child.proxy && (state.children = state.children.filter((p) => p !== child.proxy)); | ||
}; | ||
const updateValue = (value: string[]) => { | ||
emit('update:modelValue', value); | ||
emit('change', value); | ||
}; | ||
const toggleAll = (checked: boolean) => { | ||
const values: string[] = []; | ||
if (checked) { | ||
state.children.forEach((item: any) => { | ||
if (!item?.disabled) { | ||
values.push(item?.label); | ||
} | ||
}); | ||
} | ||
emit('update:modelValue', values); | ||
}; | ||
const toggleReverse = () => { | ||
const value = state.children | ||
.filter((item: any) => { | ||
if (item?.disabled) { | ||
return false; | ||
} else { | ||
return !props.modelValue.includes(item.label); | ||
} | ||
}) | ||
.map((item: any) => item.label); | ||
emit('update:modelValue', value); | ||
}; | ||
provide('parent', { | ||
value: computed(() => props.modelValue), | ||
disabled: computed(() => props.disabled), | ||
max: computed(() => props.max), | ||
updateValue, | ||
link, | ||
unlink | ||
}); | ||
watch( | ||
() => props.modelValue, | ||
(value) => { | ||
emit('change', value); | ||
} | ||
); | ||
useExpose({ toggleAll, toggleReverse }); | ||
return () => { | ||
return h( | ||
'view', | ||
{ | ||
class: componentName | ||
}, | ||
slots.default?.() | ||
); | ||
}; | ||
} | ||
}); | ||
</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,46 @@ | ||
<template> | ||
<view :class="classes" :style="style"> | ||
<slot></slot> | ||
</view> | ||
</template> | ||
<script lang="ts"> | ||
import { computed, inject } from 'vue'; | ||
import { createComponent } from '@/packages/utils/create'; | ||
const { componentName, create } = createComponent('col'); | ||
export default create({ | ||
props: { | ||
span: { | ||
type: [String, Number], | ||
default: '24' | ||
}, | ||
offset: { | ||
type: [String, Number], | ||
default: '0' | ||
} | ||
}, | ||
emits: [], | ||
setup(props) { | ||
const prefixCls = componentName; | ||
const gutter = inject('gutter') as number; | ||
const classes = computed(() => { | ||
return { | ||
[prefixCls]: true, | ||
[prefixCls + '-gutter']: gutter, | ||
['nut-col-' + props.span]: true, | ||
['nut-col-offset-' + props.offset]: true | ||
}; | ||
}); | ||
const style = computed(() => { | ||
return { | ||
paddingLeft: gutter / 2 + 'px', | ||
paddingRight: gutter / 2 + 'px' | ||
}; | ||
}); | ||
return { | ||
classes, | ||
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,47 @@ | ||
<script lang="ts"> | ||
import { h, provide, computed, readonly, watch } from 'vue'; | ||
import { createComponent } from '@/packages/utils/create'; | ||
const { componentName, create } = createComponent('radio-group'); | ||
export default create({ | ||
props: { | ||
modelValue: { | ||
type: [Number, String, Boolean], | ||
default: '' | ||
}, | ||
direction: { | ||
type: String, | ||
default: 'vertical' //horizontal | ||
}, | ||
textPosition: { | ||
type: String, | ||
default: 'right' | ||
} | ||
}, | ||
emits: ['change', 'update:modelValue'], | ||
setup(props, { emit, slots }) { | ||
const updateValue = (value: string | boolean | number) => emit('update:modelValue', value); | ||
provide('parent', { | ||
label: readonly(computed(() => props.modelValue)), | ||
position: props.textPosition, | ||
updateValue | ||
}); | ||
watch( | ||
() => props.modelValue, | ||
(value) => emit('change', value) | ||
); | ||
return () => { | ||
return h( | ||
'view', | ||
{ | ||
class: `${componentName} ${componentName}--${props.direction}` | ||
}, | ||
slots.default?.() | ||
); | ||
}; | ||
} | ||
}); | ||
</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,55 @@ | ||
<template> | ||
<view :class="classes"> | ||
<slot></slot> | ||
</view> | ||
</template> | ||
<script lang="ts"> | ||
import { provide, computed } from 'vue'; | ||
import { createComponent } from '@/packages/utils/create'; | ||
const { componentName, create } = createComponent('row'); | ||
export default create({ | ||
props: { | ||
type: { | ||
type: String, | ||
default: '' | ||
}, | ||
gutter: { | ||
type: [String, Number], | ||
default: '' | ||
}, | ||
justify: { | ||
type: String, | ||
default: 'start' | ||
}, | ||
align: { | ||
type: String, | ||
default: 'flex-start' | ||
}, | ||
flexWrap: { | ||
type: String, | ||
default: 'nowrap' | ||
} | ||
}, | ||
emits: [], | ||
setup(props) { | ||
const prefixCls = componentName; | ||
provide('gutter', props.gutter); | ||
const getClass = (prefix: string, type: string) => { | ||
return prefix ? (type ? `nut-row-${prefix}-${type}` : '') : `nut-row-${type}`; | ||
}; | ||
const classes = computed(() => { | ||
return [ | ||
prefixCls, | ||
getClass('', props.type), | ||
getClass('justify', props.justify), | ||
getClass('align', props.align), | ||
getClass('flex', props.flexWrap) | ||
]; | ||
}); | ||
return { | ||
classes | ||
}; | ||
} | ||
}); | ||
</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,42 @@ | ||
<template> | ||
<view :class="classes" @click.stop="handleClick" :ikey="ikey"> | ||
<span class="nut-side-navbar-item__title"> | ||
{{ title }} | ||
</span> | ||
</view> | ||
</template> | ||
<script lang="ts"> | ||
import { computed } from 'vue'; | ||
import { createComponent } from '@/packages/utils/create'; | ||
const { componentName, create } = createComponent('side-navbar-item'); | ||
export default create({ | ||
props: { | ||
title: { | ||
type: String, | ||
default: '' | ||
}, | ||
ikey: { | ||
type: String, | ||
default: '' | ||
} | ||
}, | ||
emits: ['click'], | ||
setup: (props: any, context: any) => { | ||
const classes = computed(() => { | ||
const prefixCls = componentName; | ||
return { | ||
[prefixCls]: true | ||
}; | ||
}); | ||
const handleClick = () => { | ||
context.emit('click'); | ||
}; | ||
return { | ||
classes, | ||
handleClick | ||
}; | ||
} | ||
}); | ||
</script> |
Oops, something went wrong.