Skip to content

Commit

Permalink
Merge pull request #92 from qianmoQ/feature-dev
Browse files Browse the repository at this point in the history
feat and fix some component
  • Loading branch information
qianmoQ authored Nov 9, 2024
2 parents b1922e0 + cd1ea49 commit ab115d6
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 138 deletions.
2 changes: 1 addition & 1 deletion CNAME
Original file line number Diff line number Diff line change
@@ -1 +1 @@
shadcn.vue.devlive.org
view-shadcn-ui.devlive.org
2 changes: 1 addition & 1 deletion docs/components/modal.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ const value = ref(false);
['title', 'The title of the dialog box. If the page header is customized using slot, the title will be invalid.', 'string', '-', '-'],
['description', 'Modal description', 'string', '-', 'title'],
['width', 'Modal width', 'number | string', '30%', '-'],
['height', 'Modal height', 'number | string', '10%', '-'],
['height', 'Modal height', 'number | string', 'auto', '-'],
['okText', 'The text of the OK button', 'string', 'OK', '-'],
['cancelText', 'The text of the Cancel button', 'string', 'Cancel', '-'],
['closable', 'Whether the dialog box can be closed', 'boolean', 'true', '-'],
Expand Down
38 changes: 38 additions & 0 deletions docs/components/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,43 @@ const defaultSelectOptions = [

:::

## Border

::: raw

<CodeRunner title="Border">
<div class="space-y-2">
<p>Select Value: {{ defaultSelect }}</p>
<ShadcnSelect v-model="defaultSelect" :options="defaultSelectOptions" />
<ShadcnSelect v-model="defaultSelect" :options="defaultSelectOptions" :border="false" />
</div>
</CodeRunner>

:::

::: details Show code

```vue
<template>
<p>Select Value: {{ defaultSelect }}</p>
<ShadcnSelect v-model="defaultSelect" :options="defaultSelectOptions" />
<ShadcnSelect v-model="defaultSelect" :options="defaultSelectOptions" :border="false" />
</template>
<script setup lang="ts">
import { ref } from 'vue';
const defaultSelect = ref('')
const defaultSelectOptions = [
{ label: 'Vue', value: 'Vue' },
{ label: 'Nuxt', value: 'Nuxt', disabled: true },
{ label: 'Svelte', value: 'Svelte' }
]
</script>
```

:::

## Group

::: raw
Expand Down Expand Up @@ -270,6 +307,7 @@ const defaultSelectOptions = [
['type', 'The type of the select', 'enum', 'default', 'primary | success | warning | error'],
['placeholder', 'The placeholder of the select', 'string', '-', '-'],
['multiple', 'Whether the select is multiple', 'boolean', 'false', 'true | false'],
['border', 'Whether the select has border', 'boolean', 'true', 'true | false'],
]">
</ApiTable>

Expand Down
27 changes: 11 additions & 16 deletions docs/components/tree.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ const data = reactive<[]>([
}
])
const generateChildNodes = (parentValue: string, level: number = 1, maxLevel: number = 3): TreeNode[] => {
const generateChildNodes = (parentValue: string, level: number = 1, maxLevel: number = 3): any[] => {
if (level >= maxLevel) {
return []
}
Expand All @@ -266,14 +266,12 @@ const generateChildNodes = (parentValue: string, level: number = 1, maxLevel: nu
}
})
}
const loadNodeData = async (node: any): Promise<any[]> => {
return new Promise((resolve) => {
setTimeout(() => {
const level = 0
const children = generateChildNodes(node.value, level)
resolve(children)
}, 1000)
})
const loadNodeData = (item: any, callback: (children: any[]) => void) => {
setTimeout(() => {
const level = 0
const children = generateChildNodes(item.value, level)
callback(children)
}, 1000)
}
</script>
```
Expand Down Expand Up @@ -543,7 +541,7 @@ export default {
]
}
])
const generateChildNodes = (parentValue: string, level: number = 1, maxLevel: number = 3): TreeNode[] => {
const generateChildNodes = (parentValue: string, level: number = 1, maxLevel: number = 3): any[] => {
if (level >= maxLevel) {
return []
}
Expand All @@ -559,15 +557,12 @@ export default {
}
})
}
const loadNodeData = async (node: TreeNode): Promise<TreeNode[]> => {
return new Promise((resolve) => {
const loadNodeData = (item: any, callback: (children: any[]) => void) => {
setTimeout(() => {
const level = 0
const children = generateChildNodes(node.value, level)
console.log('Generated children for node', node.value, ':', children)
resolve(children)
const children = generateChildNodes(item.value, level)
callback(children)
}, 1000)
})
}

return {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"author": "devlive-community",
"homepage": "https://github.com/devlive-community/view-shadcn-ui",
"private": false,
"version": "2024.2.0-alpha.1730986239",
"version": "2024.2.0-alpha.1731129825",
"license": "MIT",
"main": "./dist/view-shadcn.umd.ts",
"module": "./dist/view-shadcn.es.ts",
Expand Down
39 changes: 3 additions & 36 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,41 +1,8 @@
<template>
<div class="p-32 space-y-2">
<ShadcnSelect v-model="selected"
type="warning"
placeholder="Select options"
size="small"
:options="options"/>
<ShadcnSelect v-model="selected"
type="warning"
placeholder="Select options"
size="default"
:options="options"/>
<ShadcnSelect v-model="selected"
type="warning"
placeholder="Select options"
size="large"
:options="options"/>
</div>
<ShadcnButton disabled>Disabled</ShadcnButton>
<ShadcnButton type="danger" disabled>Disabled + Type</ShadcnButton>
<ShadcnButton type="success" size="small" disabled>Disabled + Type + Size</ShadcnButton>
</template>

<script setup lang="ts">
import { ref } from 'vue'
const selected = ref([])
const generateRandomOptions = (count) => {
const options = [] as any[]
for (let i = 1; i <= count; i++) {
options.push({
value: i,
label: `Option ${ i }`
})
}
return options
}
const options = generateRandomOptions(30)
</script>
58 changes: 41 additions & 17 deletions src/ui/button/ShadcnButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,37 @@ const getHoverClass = computed(() => {
return hoverColorMap[props.type]
})
// New computed property for type styles including hover
const getTypeStyles = computed(() => {
// If disabled or loading, don't include hover styles
if (props.disabled || props.loading) {
return props.type === 'default'
? [
'bg-white',
'border-solid border border-gray-200',
'text-gray-500'
]
: [
ButtonBackgroundType[props.type],
props.type === 'text' ? 'text-gray-500' : 'text-white'
]
}
// Normal state with hover effects
return props.type === 'default'
? [
'bg-white',
'border-solid border border-gray-200',
'text-gray-500',
'hover:border-gray-300'
]
: [
ButtonBackgroundType[props.type],
ButtonHoverType[props.type],
props.type === 'text' ? 'text-gray-500' : 'text-white'
]
})
const buttonGroupSize = inject<ComputedRef<keyof typeof ButtonSize> | undefined>(
'buttonGroupSize',
undefined
Expand All @@ -123,23 +154,16 @@ const buttonProps = computed(() => ({
'inline-flex items-center justify-center whitespace-nowrap transition-colors',
// Size
!props.circle && ButtonSize[finalSize.value],
// Type style
props.ghost ? [
'bg-transparent',
'border-solid border',
getBorderColorClass.value,
getTextColorClass.value,
getHoverClass.value
] : props.type === 'default' ? [
'bg-white',
'border-solid border border-gray-200',
'text-gray-500',
'hover:border-gray-300'
] : [
ButtonBackgroundType[props.type],
ButtonHoverType[props.type],
props.type === 'text' ? 'text-gray-500' : 'text-white'
],
// Type style with conditional hover
props.ghost
? [
'bg-transparent',
'border-solid border',
getBorderColorClass.value,
getTextColorClass.value,
!props.disabled && !props.loading && getHoverClass.value
]
: getTypeStyles.value,
// Rounded corners
{ 'rounded-full': props.round || props.circle },
{ 'rounded-md': !props.round && !props.circle },
Expand Down
2 changes: 1 addition & 1 deletion src/ui/modal/ShadcnModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const props = withDefaults(defineProps<ModalProps>(), {
cancelText: 'Cancel',
closable: true,
width: '30%',
height: '10%',
height: 'auto',
maskClosable: true
})
Expand Down
61 changes: 4 additions & 57 deletions src/ui/select/ShadcnSelect.vue
Original file line number Diff line number Diff line change
@@ -1,61 +1,7 @@
<!--<template>-->
<!-- <div ref="selectRef" class="relative">-->
<!-- <div :class="['flex items-center justify-between border rounded px-2 py-1',-->
<!-- Size[size],-->
<!-- {-->
<!-- 'cursor-pointer': !disabled,-->
<!-- 'cursor-not-allowed opacity-50 bg-gray-100': disabled,-->
<!-- [HoverType[type]]: true-->
<!-- }-->
<!-- ]"-->
<!-- @click="toggleDropdown">-->
<!-- <div class="flex flex-wrap gap-1 flex-1">-->
<!-- <slot name="selected">-->
<!-- <template v-if="multiple && selectedLabels.length">-->
<!-- <span v-for="(label, _index) in selectedLabels"-->
<!-- :key="_index"-->
<!-- class="bg-gray-100 px-2 py-1 rounded-md text-sm flex items-center gap-1">-->
<!-- {{ label }}-->
<!-- <button class="hover:text-red-500" @click.stop="removeSelection(_index)">-->
<!-- ×-->
<!-- </button>-->
<!-- </span>-->
<!-- </template>-->
<!-- <template v-else>-->
<!-- {{ selectedLabels[0] || placeholder }}-->
<!-- </template>-->
<!-- </slot>-->
<!-- </div>-->

<!-- <svg :class="['w-4 h-4 transition-transform duration-200 ml-1',-->
<!-- { 'rotate-180': isExpanded }]"-->
<!-- fill="currentColor"-->
<!-- viewBox="0 0 20 20"-->
<!-- xmlns="http://www.w3.org/2000/svg">-->
<!-- <path clip-rule="evenodd"-->
<!-- d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"-->
<!-- fill-rule="evenodd"/>-->
<!-- </svg>-->
<!-- </div>-->

<!-- <div v-show="isExpanded"-->
<!-- class="absolute z-10 bg-white border border-gray-300 rounded-sm mt-1 w-full py-2 px-2 space-y-1 overflow-y-auto max-h-60">-->
<!-- <slot name="options">-->
<!-- <ShadcnSelectOption v-for="(option, index) in internalOptions"-->
<!-- :key="index"-->
<!-- :value="option.value"-->
<!-- :label="option.label"-->
<!-- :selected="isOptionSelected(option.value)"-->
<!-- :disabled="option.disabled"-->
<!-- :type="type"/>-->
<!-- </slot>-->
<!-- </div>-->
<!-- </div>-->
<!--</template>-->

<template>
<div ref="selectRef" class="relative">
<div :class="['flex border rounded px-2',
<div :class="['flex rounded px-2',
border && 'border',
{
'cursor-pointer': !disabled,
'cursor-not-allowed opacity-50 bg-gray-100': disabled,
Expand Down Expand Up @@ -131,7 +77,8 @@ const props = withDefaults(defineProps<SelectProps>(), {
disabled: false,
size: 'default',
type: 'primary',
multiple: false
multiple: false,
border: true
})
const isExpanded = ref(false)
Expand Down
1 change: 1 addition & 0 deletions src/ui/select/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface SelectProps
size?: keyof typeof Size
type?: keyof typeof HoverType
multiple?: boolean
border?: boolean
}

export interface SelectOptionProps
Expand Down
19 changes: 12 additions & 7 deletions src/ui/tree/ShadcnTreeNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
</template>

<script setup lang="ts">
import { computed, nextTick, ref, watch } from 'vue'
import { computed, ref, watch } from 'vue'
import { TreeNode, TreeNodeEmits, TreeNodeProps } from './types'
import ShadcnCheckbox from '@/ui/checkbox'
Expand Down Expand Up @@ -155,16 +155,21 @@ const onExpand = async (event: Event) => {
if (!hasChildren.value && props.node.isLeaf === false && !isExpanded.value && props.loadData) {
loading.value = true
try {
// Get the child node data and update it
props.node.children = await props.loadData(props.node)
await nextTick()
// Use callbacks to load data
props.loadData(props.node, (children: TreeNode[]) => {
props.node.children = children
loading.value = false
isExpanded.value = true
})
}
finally {
catch (error) {
console.error('Failed to load children:', error)
loading.value = false
}
}
isExpanded.value = !isExpanded.value
else {
isExpanded.value = !isExpanded.value
}
emit('on-expand', props.node)
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/tree/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface TreeNodeProps
checkable?: boolean
cascade?: boolean
showLine?: boolean
loadData?: (node: TreeNode) => Promise<TreeNode[]>
loadData?: (node: TreeNode, callback: (children: TreeNode[]) => void) => void
}

export type TreeEmits = {
Expand Down

0 comments on commit ab115d6

Please sign in to comment.