@popgrids/ui 0.0.33 → 0.0.35

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/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Avatar as Avatar$1 } from '@base-ui/react/avatar';
2
2
  import { cva } from 'class-variance-authority';
3
+ import { createContext, useContext } from 'react';
3
4
  import { clsx } from 'clsx';
4
5
  import { twMerge } from 'tailwind-merge';
5
6
  import { mergeProps } from '@base-ui/react/merge-props';
@@ -88,8 +89,59 @@ var avatarVariants = cva(
88
89
  }
89
90
  }
90
91
  );
91
- function Avatar({ className = "", size = "md", ...props }) {
92
- return /* @__PURE__ */ jsx(
92
+ function fnv1a32(data) {
93
+ const bytes = new TextEncoder().encode(data);
94
+ let h = 2166136261;
95
+ for (let i = 0; i < bytes.length; i++) {
96
+ h ^= bytes[i];
97
+ h = Math.imul(h, 16777619);
98
+ }
99
+ return h >>> 0;
100
+ }
101
+ var BACKGROUND_COLORS = [
102
+ "#DDD0BE",
103
+ "#E9DCBB",
104
+ "#E9DCBB",
105
+ "#C7D1B0",
106
+ "#C6D0CB",
107
+ "#E9DCBB",
108
+ "#C7D1B0",
109
+ "#E9DCBB",
110
+ "#DFC2C0",
111
+ "#CFD4C6",
112
+ "#D7E3E8",
113
+ "#CFD4C6",
114
+ "#D6B3B3",
115
+ "#E9DCBB",
116
+ "#CFCBDC",
117
+ "#BFD6D7",
118
+ "#E3D2C6",
119
+ "#D1E2E7",
120
+ "#D6B3B3",
121
+ "#BFD6D7",
122
+ "#E9DCBB",
123
+ "#C7D1B0",
124
+ "#DFC2C0",
125
+ "#D1E2E7",
126
+ "#CFD4C6",
127
+ "#E9DCBB",
128
+ "#D7E3E8",
129
+ "#CFD4C6",
130
+ "#C6D0CB",
131
+ "#E9DCBB",
132
+ "#C7D1B0",
133
+ "#E9DCBB",
134
+ "#CFCBDC",
135
+ "#E3D2C6",
136
+ "#E9DCBB"
137
+ ];
138
+ function backgroundColor(id) {
139
+ return BACKGROUND_COLORS[fnv1a32(id) % BACKGROUND_COLORS.length];
140
+ }
141
+ var AvatarColorContext = createContext(void 0);
142
+ function Avatar({ className = "", size = "md", colorKey, ...props }) {
143
+ const resolvedColor = colorKey ? backgroundColor(colorKey) : void 0;
144
+ return /* @__PURE__ */ jsx(AvatarColorContext.Provider, { value: resolvedColor, children: /* @__PURE__ */ jsx(
93
145
  Avatar$1.Root,
94
146
  {
95
147
  "data-slot": "avatar",
@@ -97,28 +149,41 @@ function Avatar({ className = "", size = "md", ...props }) {
97
149
  className: cn(avatarVariants({ size }), className),
98
150
  ...props
99
151
  }
100
- );
152
+ ) });
101
153
  }
102
- function AvatarImage({ className = "", ...props }) {
154
+ function AvatarImage({ className = "", style, ...props }) {
155
+ const resolvedColor = useContext(AvatarColorContext);
156
+ const mergedStyle = resolvedColor ? { ...style, backgroundColor: resolvedColor } : style;
103
157
  return /* @__PURE__ */ jsx(
104
158
  Avatar$1.Image,
105
159
  {
106
160
  "data-slot": "avatar-image",
107
- className: cn("aspect-square size-full mask mask-squircle object-cover", className),
108
- ...props
161
+ className: cn("mask mask-squircle aspect-square size-full object-cover", className),
162
+ ...props,
163
+ style: mergedStyle
109
164
  }
110
165
  );
111
166
  }
112
- function AvatarFallback({ className = "", ...props }) {
167
+ function AvatarFallback({ className = "", style, ...props }) {
168
+ const resolvedColor = useContext(AvatarColorContext);
169
+ const mergedStyle = resolvedColor ? { ...style, backgroundColor: resolvedColor } : style;
113
170
  return /* @__PURE__ */ jsx(
114
171
  Avatar$1.Fallback,
115
172
  {
116
173
  "data-slot": "avatar-fallback",
117
174
  className: cn(
118
- "mask mask-squircle flex size-full items-center justify-center bg-muted text-muted-foreground text-sm group-data-[size=sm]/avatar:text-xs",
175
+ "mask mask-squircle text-muted-foreground flex size-full items-center justify-center text-sm group-data-[size=sm]/avatar:text-xs",
176
+ resolvedColor ? void 0 : "bg-muted",
177
+ "group-data-[size=xs]/avatar:text-xs",
178
+ "group-data-[size=sm]/avatar:text-sm",
179
+ "group-data-[size=md]/avatar:text-lg",
180
+ "group-data-[size=lg]/avatar:text-2xl",
181
+ "group-data-[size=xl]/avatar:text-4xl",
182
+ "group-data-[size=xxl]/avatar:text-5xl",
119
183
  className
120
184
  ),
121
- ...props
185
+ ...props,
186
+ style: mergedStyle
122
187
  }
123
188
  );
124
189
  }
@@ -128,7 +193,7 @@ function AvatarBadge({ className = "", ...props }) {
128
193
  {
129
194
  "data-slot": "avatar-badge",
130
195
  className: cn(
131
- "absolute h-[18px] min-w-[18px] z-10 select-none",
196
+ "absolute z-10 h-[18px] min-w-[18px] select-none",
132
197
  "leading-none",
133
198
  "group-data-[size=xs]/avatar:right-[-4px] group-data-[size=xs]/avatar:bottom-[-4px]",
134
199
  "group-data-[size=sm]/avatar:right-[-4px] group-data-[size=sm]/avatar:bottom-[-4px]",
@@ -148,7 +213,7 @@ function AvatarGroup({ className = "", ...props }) {
148
213
  {
149
214
  "data-slot": "avatar-group",
150
215
  className: cn(
151
- "group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2 *:data-[slot=avatar]:ring-background",
216
+ "group/avatar-group *:data-[slot=avatar]:ring-background flex -space-x-2 *:data-[slot=avatar]:ring-2",
152
217
  className
153
218
  ),
154
219
  ...props
@@ -161,7 +226,7 @@ function AvatarGroupCount({ className = "", ...props }) {
161
226
  {
162
227
  "data-slot": "avatar-group-count",
163
228
  className: cn(
164
- "relative flex size-8 shrink-0 items-center justify-center rounded-full bg-muted text-muted-foreground text-sm ring-2 ring-background group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3",
229
+ "bg-muted text-muted-foreground ring-background relative flex size-8 shrink-0 items-center justify-center rounded-full text-sm ring-2 group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3",
165
230
  className
166
231
  ),
167
232
  ...props