@mekari/pixel3-rating 0.0.1-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/rating.js ADDED
@@ -0,0 +1,251 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/rating.tsx
22
+ var rating_exports = {};
23
+ __export(rating_exports, {
24
+ MpRating: () => MpRating
25
+ });
26
+ module.exports = __toCommonJS(rating_exports);
27
+ var import_vue2 = require("vue");
28
+ var import_vue3 = require("vue");
29
+ var import_pixel3_text = require("@mekari/pixel3-text");
30
+
31
+ // src/modules/rating.hooks.ts
32
+ var import_vue = require("vue");
33
+ var import_pixel3_utils = require("@mekari/pixel3-utils");
34
+ var import_recipes = require("@mekari/pixel3-styled-system/recipes");
35
+ var import_tokens = require("@mekari/pixel3-styled-system/tokens");
36
+ var ICON_STAR_PATH = "M11.9977 1.25C13.0469 1.25 13.8734 2.04226 14.4011 3.11146L16.1635 6.66513C16.217 6.77509 16.3436 6.92995 16.5341 7.07161C16.7243 7.21313 16.9106 7.2912 17.0332 7.3118L20.2232 7.84612C21.3754 8.03972 22.3412 8.60445 22.6548 9.58788C22.968 10.5705 22.5091 11.5915 21.6805 12.4216L21.6796 12.4225L19.2014 14.9209C19.1032 15.0199 18.9932 15.2065 18.9242 15.4495C18.8556 15.6908 18.8496 15.9106 18.8806 16.0527L19.5901 19.1454C19.8841 20.4318 19.7867 21.7073 18.8794 22.3742C17.969 23.0433 16.7249 22.7467 15.5946 22.0736L12.6043 20.289C12.4787 20.214 12.263 20.1532 12.0027 20.1532C11.7444 20.1532 11.5242 20.2132 11.3904 20.2909L8.40401 22.0732C7.27505 22.7487 6.03249 23.04 5.12202 22.3702C4.21532 21.7032 4.11294 20.43 4.40795 19.1447L5.11725 16.0527C5.14833 15.9107 5.14225 15.6908 5.07371 15.4495C5.00471 15.2065 4.89469 15.0199 4.79646 14.9209L2.31646 12.4207C1.49318 11.5907 1.03566 10.5704 1.34645 9.58923C1.65814 8.60521 2.62207 8.03979 3.77504 7.84606L6.96334 7.31202C7.08022 7.29177 7.26382 7.21456 7.45365 7.07266C7.64381 6.93051 7.77081 6.77532 7.82434 6.66513L9.58704 3.11094L9.58773 3.10954C10.1205 2.04102 10.9496 1.25 11.9977 1.25Z";
37
+ var ICON_HEART_PATH = "M7.56 2.25C4.06443 2.25 1.25 5.12533 1.25 8.65281C1.25 12.4387 2.98665 15.4297 5.06285 17.5808C7.12835 19.7209 9.57334 21.078 11.132 21.6168C11.4072 21.7143 11.7221 21.75 12 21.75C12.2779 21.75 12.5928 21.7143 12.868 21.6168C14.4267 21.078 16.8716 19.7209 18.9371 17.5808C21.0133 15.4297 22.75 12.4387 22.75 8.65281C22.75 5.12533 19.9356 2.25 16.44 2.25C15.2736 2.25 14.2461 2.85744 13.4328 3.55225C12.8969 4.01011 12.4142 4.54017 12.0004 5.04802C11.5876 4.54051 11.1064 4.01049 10.5714 3.55265C9.75846 2.85694 8.73097 2.25 7.56 2.25Z";
38
+ function useRating(props, emit) {
39
+ const {
40
+ id,
41
+ color,
42
+ modelValue,
43
+ maxValue,
44
+ variant,
45
+ isReadOnly
46
+ } = (0, import_vue.toRefs)(props);
47
+ const getId = id.value || (0, import_pixel3_utils.getUniqueId)("", "rating").value;
48
+ const iconWidth = (0, import_vue.ref)("0%");
49
+ const rating = (0, import_vue.ref)(0);
50
+ const rootAttrs = (0, import_vue.computed)(() => {
51
+ return {
52
+ "data-pixel-component": "MpRating",
53
+ id: getId,
54
+ class: (0, import_recipes.ratingSlotRecipe)().root,
55
+ style: {
56
+ cursor: isReadOnly.value ? "default" : "pointer"
57
+ },
58
+ onMouseleave: handleMouseLeave
59
+ };
60
+ });
61
+ const wrapperAttrs = (0, import_vue.computed)(() => {
62
+ return {
63
+ class: (0, import_recipes.ratingSlotRecipe)().wrapper
64
+ };
65
+ });
66
+ const valueAttrs = (0, import_vue.computed)(() => {
67
+ return {
68
+ class: (0, import_recipes.ratingSlotRecipe)().value
69
+ };
70
+ });
71
+ const backgroundIconWrapperAttrs = (0, import_vue.computed)(() => {
72
+ return {
73
+ id: `${getId}--background-icon-wrapper`,
74
+ class: (0, import_recipes.ratingSlotRecipe)().backgroundIconWrapper
75
+ };
76
+ });
77
+ const activeIconWrapperAttrs = (0, import_vue.computed)(() => {
78
+ return {
79
+ id: `${getId}--active-icon-wrapper`,
80
+ class: (0, import_recipes.ratingSlotRecipe)().activeIconWrapper,
81
+ style: {
82
+ width: iconWidth.value
83
+ }
84
+ };
85
+ });
86
+ const iconAttrs = /* @__PURE__ */ __name((i) => {
87
+ const propColor = (0, import_tokens.token)(`colors.${color.value}`) || color.value;
88
+ return {
89
+ id: `${getId}--icon-${i}`,
90
+ key: `icon-${i}`,
91
+ xmlns: "http://www.w3.org/2000/svg",
92
+ viewBox: "0 0 24 24",
93
+ innerHTML: `<path d="${getVariant.value}" fill="currentColor" />`,
94
+ "data-variant": variant.value,
95
+ style: {
96
+ color: propColor
97
+ },
98
+ onClick: () => handleClick(i),
99
+ onMouseenter: () => handleMMouseEnter(i)
100
+ };
101
+ }, "iconAttrs");
102
+ const getVariant = (0, import_vue.computed)(() => {
103
+ if (variant.value === "heart") {
104
+ return ICON_HEART_PATH;
105
+ }
106
+ return ICON_STAR_PATH;
107
+ });
108
+ function handleWidth(value) {
109
+ const result = value / maxValue.value * 100;
110
+ if (value > maxValue.value) {
111
+ iconWidth.value = "100%";
112
+ } else if (value < 0) {
113
+ iconWidth.value = "0%";
114
+ } else {
115
+ iconWidth.value = `${result}%`;
116
+ }
117
+ }
118
+ __name(handleWidth, "handleWidth");
119
+ function handleClick(i) {
120
+ if (isReadOnly.value) {
121
+ return;
122
+ }
123
+ rating.value = i + 1;
124
+ emit("click-rating", rating.value);
125
+ emit("update:modelValue", rating.value);
126
+ }
127
+ __name(handleClick, "handleClick");
128
+ function handleMMouseEnter(i) {
129
+ if (isReadOnly.value) {
130
+ return;
131
+ }
132
+ rating.value = i + 1;
133
+ handleWidth(rating.value);
134
+ emit("hover-rating", rating.value);
135
+ }
136
+ __name(handleMMouseEnter, "handleMMouseEnter");
137
+ function handleMouseLeave() {
138
+ if (isReadOnly.value) {
139
+ return;
140
+ }
141
+ rating.value = modelValue.value;
142
+ handleWidth(rating.value);
143
+ emit("hover-rating", rating.value);
144
+ }
145
+ __name(handleMouseLeave, "handleMouseLeave");
146
+ (0, import_vue.watch)(() => modelValue.value, (newValue) => {
147
+ handleWidth(newValue);
148
+ }, {
149
+ immediate: true
150
+ });
151
+ return {
152
+ rootAttrs,
153
+ wrapperAttrs,
154
+ valueAttrs,
155
+ backgroundIconWrapperAttrs,
156
+ activeIconWrapperAttrs,
157
+ iconAttrs
158
+ };
159
+ }
160
+ __name(useRating, "useRating");
161
+
162
+ // src/rating.tsx
163
+ var import_pixel3_utils2 = require("@mekari/pixel3-utils");
164
+
165
+ // src/modules/rating.props.ts
166
+ var ratingProps = {
167
+ id: {
168
+ type: String,
169
+ default: ""
170
+ },
171
+ modelValue: {
172
+ type: Number,
173
+ default: 2
174
+ },
175
+ maxValue: {
176
+ type: Number,
177
+ default: 5
178
+ },
179
+ variant: {
180
+ type: String,
181
+ default: "star"
182
+ },
183
+ color: {
184
+ type: String,
185
+ default: ""
186
+ },
187
+ isShowValue: {
188
+ type: Boolean,
189
+ default: false
190
+ },
191
+ isReadOnly: {
192
+ type: Boolean,
193
+ default: false
194
+ }
195
+ };
196
+ var ratingEmit = ["click-rating", "hover-rating", "update:modelValue"];
197
+
198
+ // src/rating.tsx
199
+ function _isSlot(s) {
200
+ return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !(0, import_vue2.isVNode)(s);
201
+ }
202
+ __name(_isSlot, "_isSlot");
203
+ var MpRating = (0, import_vue3.defineComponent)({
204
+ name: "MpRating",
205
+ props: ratingProps,
206
+ emit: ratingEmit,
207
+ setup(props, {
208
+ slots,
209
+ emit
210
+ }) {
211
+ const {
212
+ rootAttrs,
213
+ wrapperAttrs,
214
+ valueAttrs,
215
+ backgroundIconWrapperAttrs,
216
+ activeIconWrapperAttrs,
217
+ iconAttrs
218
+ } = useRating(props, emit);
219
+ return () => {
220
+ const children = slots.default && slots.default();
221
+ const {
222
+ modelValue,
223
+ maxValue,
224
+ isShowValue
225
+ } = props;
226
+ const {
227
+ isNextTheme
228
+ } = (0, import_pixel3_utils2.usePixelTheme)();
229
+ const icon = [];
230
+ for (let i = 0; i < maxValue; i++) {
231
+ icon.push((0, import_vue3.h)("svg", {
232
+ ...iconAttrs(i)
233
+ }));
234
+ }
235
+ return (0, import_vue2.createVNode)("div", rootAttrs.value, [(0, import_vue2.createVNode)("div", wrapperAttrs.value, [(0, import_vue2.createVNode)("div", backgroundIconWrapperAttrs.value, [icon.map((icon2) => icon2)]), (0, import_vue2.createVNode)("div", activeIconWrapperAttrs.value, [icon.map((icon2) => icon2)])]), isShowValue && (0, import_vue2.createVNode)("div", valueAttrs.value, [children || (0, import_vue2.createVNode)(import_vue2.Fragment, null, [(0, import_vue2.createVNode)(import_pixel3_text.MpText, {
236
+ "weight": "semiBold"
237
+ }, {
238
+ default: () => [`${modelValue} /`, (0, import_vue2.createTextVNode)("\xA0")]
239
+ }), (0, import_vue2.createVNode)(import_pixel3_text.MpText, {
240
+ "weight": "semiBold",
241
+ "color": isNextTheme ? "text.disabled" : "gray.400"
242
+ }, _isSlot(maxValue) ? maxValue : {
243
+ default: () => [maxValue]
244
+ })])])]);
245
+ };
246
+ }
247
+ });
248
+ // Annotate the CommonJS export names for ESM import in node:
249
+ 0 && (module.exports = {
250
+ MpRating
251
+ });
@@ -0,0 +1,9 @@
1
+ import {
2
+ MpRating
3
+ } from "./chunk-TMJBERQJ.mjs";
4
+ import "./chunk-5G32PRK5.mjs";
5
+ import "./chunk-KTMGMPBN.mjs";
6
+ import "./chunk-QZ7VFGWC.mjs";
7
+ export {
8
+ MpRating
9
+ };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@mekari/pixel3-rating",
3
+ "description": "Mekari Pixel 3 | Rating provide insight regarding others opinions and experiences component.",
4
+ "version": "0.0.1-dev.0",
5
+ "main": "dist/index.js",
6
+ "license": "MIT",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "dependencies": {
11
+ "@mekari/pixel3-text": "0.0.18-dev.0",
12
+ "@mekari/pixel3-styled-system": "0.1.4-dev.0",
13
+ "@mekari/pixel3-utils": "0.0.7"
14
+ },
15
+ "peerDependencies": {
16
+ "vue": "^3.4.9"
17
+ },
18
+ "devDependencies": {
19
+ "vue": "^3.4.9"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "module": "dist/index.mjs",
25
+ "types": "dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "require": "./dist/index.js",
30
+ "default": "./dist/index.mjs"
31
+ }
32
+ },
33
+ "scripts": {
34
+ "clean": "rimraf dist .turbo",
35
+ "build": "tsup && pnpm build:types",
36
+ "build:fast": "tsup",
37
+ "build:types": "tsup src --dts-only",
38
+ "types:check": "tsc --noEmit",
39
+ "replace-config": "clean-package",
40
+ "restore-config": "clean-package restore"
41
+ }
42
+ }