diff --git a/CHANGELOG.md b/CHANGELOG.md index eab8051..35ea41a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.1.2 + +### Patch Changes + +- Update doc, default values and convert string rating size in number to improve retro-compatibility + ## 0.1.1 ### Patch Changes diff --git a/README.md b/README.md index d5ac6bd..90d4caf 100644 --- a/README.md +++ b/README.md @@ -66,12 +66,12 @@ export default defineNuxtConfig({ The following props can be passed to customize the appearance and behavior of the component: - `ratingCount` (optional, default: 5): The total number of rating levels available. -- `ratingSize` (optional, default: "32px"): The size of the rating meter. -- `ratingSpacing` (optional, default: 0): The spacing between the rating levels. -- `ratingStep` (optional, default: 0): Defines the increment between rating levels. For example, with ratingStep set to 0.5, users can select ratings like 0.5, 1, 1.5, etc. +- `ratingSize` (optional, default: 15): The size of the rating meter. +- `ratingSpacing` (optional, default: 2): The spacing between the rating levels. +- `ratingStep` (optional, default: 0.1): Defines the increment between rating levels. For example, with ratingStep set to 0.5, users can select ratings like 0.5, 1, 1.5, etc. - `activeColor` (optional, default: "#ffc700"): The color of the active rating level. - `inactiveColor` (optional, default: "gray"): The color of the inactive rating levels. -- `ratingValue` (optional, default: 3.7): The initial rating value. +- `ratingValue` (optional, default: 4.5): The initial rating value. - `ratingContent` (optional, default: "[19.8, 2.2, 6.6, 43.56, 39.6, 17.16, 0, 17.16, 33, 43.56]"): The content to be displayed for each rating level, should be polygon points see https://developer.mozilla.org/fr/docs/Web/SVG/Element/polygon. - `readOnly` (optional, default: true): Specifies whether the rating meter is read-only or interactive. - `borderColor` (optional, default: "#db8403"): The border color of the stars. diff --git a/package.json b/package.json index 1d59622..675e50b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nuxt-rating", - "version": "0.1.1", + "version": "0.1.2", "description": "Display or retrieve a score on a fully customisable scale.", "homepage": "https://github.com/Aurion72/nuxt-rating#readme", "repository": "Aurion72/nuxt-rating", diff --git a/playground/app.vue b/playground/app.vue index 97681a9..8ea30f8 100644 --- a/playground/app.vue +++ b/playground/app.vue @@ -8,14 +8,14 @@ diff --git a/src/runtime/components/NuxtRating.vue b/src/runtime/components/NuxtRating.vue index b259f08..41677d6 100644 --- a/src/runtime/components/NuxtRating.vue +++ b/src/runtime/components/NuxtRating.vue @@ -36,16 +36,16 @@ } const props = withDefaults(defineProps(), { - ratingStep: 1, - ratingValue: 0, + ratingStep: 0.1, + ratingValue: 4.5, roundStartRating: true, activeColor: '#ffa41c', inactiveColor: '#d8d8d8', ratingCount: 5, ratingContent: () => [19.8, 2.2, 6.6, 43.56, 39.6, 17.16, 0, 17.16, 33, 43.56], - ratingSize: 50, + ratingSize: 15, ratingSpacing: 2, - readOnly: false, + readOnly: true, inline: false, borderColor: '#db8403', borderWidth: 0, diff --git a/src/runtime/components/NuxtStar.vue b/src/runtime/components/NuxtStar.vue index 7b4b37d..2fe2802 100644 --- a/src/runtime/components/NuxtStar.vue +++ b/src/runtime/components/NuxtStar.vue @@ -53,11 +53,19 @@ const isReady = ref(false) const isStarActive = ref(true) + const parseSize = (size: string | number): number => { + if (typeof size === 'number') return size + const value = parseFloat(size) + return isNaN(value) ? 0 : value + } + + const size = parseSize(props.size) + const starPointsToString = computed(() => props.points.join(',')) const gradId = computed(() => `url(#${grad.value})`) - const starSize = computed( - () => props.size + (props.roundedCorners && props.borderWidth <= 0 ? 6 : props.borderWidth), - ) + const starSize = computed(() => { + return size + (props.roundedCorners && props.borderWidth <= 0 ? 6 : props.borderWidth) + }) const starFill = computed(() => `${props.fill}%`) const getBorderColor = computed(() => props.fill <= 0 @@ -95,7 +103,7 @@ } const getPosition = (event: MouseEvent) => { - const starWidth = (92 / 100) * props.size + const starWidth = (92 / 100) * size const offset = Math.max(event.offsetX, 1) return Math.min(Math.round((100 / starWidth) * offset), 100) } diff --git a/src/runtime/types/nuxt-rating.d.ts b/src/runtime/types/nuxt-rating.d.ts index 7c44a9e..e6c1c66 100644 --- a/src/runtime/types/nuxt-rating.d.ts +++ b/src/runtime/types/nuxt-rating.d.ts @@ -6,7 +6,7 @@ export type NuxtRatingProps = { inactiveColor?: string ratingCount?: number ratingContent?: number[] - ratingSize?: number + ratingSize?: number | string ratingSpacing?: number readOnly?: boolean inline?: boolean diff --git a/src/runtime/types/nuxt-star.d.ts b/src/runtime/types/nuxt-star.d.ts index 71c9697..0089227 100644 --- a/src/runtime/types/nuxt-star.d.ts +++ b/src/runtime/types/nuxt-star.d.ts @@ -1,7 +1,7 @@ export type NuxtStarProps = { fill: number points: number[] - size: number + size: number | string starId: number activeColor: string inactiveColor: string diff --git a/test/fixtures/basic/app.vue b/test/fixtures/basic/app.vue index 5a5dac8..e27cf85 100644 --- a/test/fixtures/basic/app.vue +++ b/test/fixtures/basic/app.vue @@ -4,6 +4,8 @@ {{ rating }} diff --git a/test/rendering.test.ts b/test/rendering.test.ts index 8cd5bec..f562c45 100644 --- a/test/rendering.test.ts +++ b/test/rendering.test.ts @@ -12,7 +12,7 @@ describe('test module', async () => { const html = await $fetch('/') expect(html).toContain('class="nuxt-rating-wrapper"') - console.log('html', html.res) + console.log('html', html) }) describe('test module with playwright', async () => { @@ -36,9 +36,13 @@ describe('test module', async () => { const ratingValue = await page.$('.rating-value') expect(ratingValue).not.toBeNull() - const textContent = await ratingValue.innerText() - expect(textContent).toContain('3') + if (ratingValue) { + const textContent = await ratingValue.innerText() + expect(textContent).toContain('3') + } else { + throw new Error('ratingValue element is null') + } }) afterAll(async () => {