-
Notifications
You must be signed in to change notification settings - Fork 50
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
1 parent
156224e
commit 5e3b88c
Showing
13 changed files
with
233 additions
and
67 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,5 @@ | ||
import { withInstall } from '@onu-ui/utils' | ||
import Rate from './src/index.vue' | ||
|
||
export const ORate = withInstall(Rate) | ||
export default ORate |
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,68 @@ | ||
<script lang="ts" setup name="O-Rate"> | ||
import { computed } from 'vue' | ||
import OIcon from '../../icon/src/index.vue' | ||
import { rateProps } from './props' | ||
const props = defineProps(rateProps) | ||
const emits = defineEmits(['update:modelValue', 'change']) | ||
const curVal = ref(props.modelValue) | ||
const isAtLeftHalf = ref(false) | ||
const setCurValue = (item:number, e:MouseEvent) => { | ||
if (props.readonly) return | ||
if (props.allowHalf) { | ||
const target = e.target as HTMLElement | ||
isAtLeftHalf.value = e.offsetX * 2 <= target.clientWidth | ||
} | ||
curVal.value = isAtLeftHalf.value ? item - 0.5 : item | ||
} | ||
const resetCurValue = () => { | ||
if (props.readonly) return | ||
curVal.value = props.modelValue | ||
} | ||
watch(() => props.modelValue, () => { | ||
resetCurValue() | ||
}, | ||
{ immediate: true }) | ||
const selectVal = () => { | ||
if (props.readonly) return | ||
emits('update:modelValue', curVal.value) | ||
emits('change', curVal.value) | ||
} | ||
const showFilledIcon = computed(() => { | ||
return function(val, item) { | ||
return !(Math.round(val) < item) | ||
} | ||
}) | ||
const showHalfIcon = computed(() => { | ||
return function(val, item) { | ||
return (Math.round(val) === item) && val < item | ||
} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="o-rate"> | ||
<span | ||
v-for="(item, key) in maxValue" | ||
:key="key" | ||
@mousemove="setCurValue(item, $event)" | ||
@mouseleave="resetCurValue" | ||
@click="selectVal" | ||
> | ||
<o-icon | ||
v-show="showFilledIcon(curVal, item)" | ||
:class="showHalfIcon(curVal, item) ? 'o-rate-half' : ''" | ||
name="o-rate-icon i-carbon-star-filled" | ||
:o="color" | ||
/> | ||
<o-icon v-show="!showFilledIcon(curVal, item)" name="o-rate-icon i-carbon-star" :o="voidColor" /> | ||
</span> | ||
<span class="o-rate-text">{{ text }}</span> | ||
</div> | ||
</template> |
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,31 @@ | ||
import type { ExtractPropTypes } from 'vue' | ||
|
||
export const rateProps = { | ||
modelValue: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
maxValue: { | ||
type: Number, | ||
default: 5, | ||
}, | ||
readonly: Boolean, | ||
text: { | ||
type: String, | ||
default: '', | ||
}, | ||
color: { | ||
type: String, | ||
default: 'warning', | ||
}, | ||
voidColor: { | ||
type: String, | ||
default: '', | ||
}, | ||
allowHalf: { | ||
type: Boolean, | ||
default: false, | ||
}, | ||
} as const | ||
|
||
export type ORateProps = ExtractPropTypes<typeof rateProps> |
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,7 @@ | ||
export const rateShortcuts: Record<string, string> = { | ||
// Rate | ||
'o-rate': 'f-c cursor-pointer', | ||
'o-rate-icon': 'text-xl m-1 !w-5 !h-5', | ||
'o-rate-text': 'leading-5', | ||
'o-rate-half': 'o-bg-clip-half', | ||
} |
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,14 @@ | ||
<script lang="ts" setup> | ||
const rate = ref(2.5) | ||
</script> | ||
|
||
<template> | ||
<OCard o-white title="Rate"> | ||
<div space-y-2> | ||
<div fsc gap-4> | ||
{{ rate }} | ||
<o-rate v-model="rate" :max-value="10" text="123123" allow-half /> | ||
</div> | ||
</div> | ||
</OCard> | ||
</template> |
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 |
---|---|---|
|
@@ -10,5 +10,6 @@ | |
<TheBadge /> | ||
<TheTag /> | ||
<TheMessage /> | ||
<TheRate /> | ||
</div> | ||
</template> |
Oops, something went wrong.