oneslash-design-system 1.1.29 → 1.1.31

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.
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import React, { useState, useEffect, JSX } from 'react';
2
+ import React, { useState, useEffect } from 'react';
3
3
  import * as HeroIcons from '@heroicons/react/24/outline';
4
4
 
5
5
  interface TagProps {
@@ -8,10 +8,8 @@ interface TextFieldProps {
8
8
  onChange: (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;// Specify the event type for both input and textarea
9
9
  onBlur?: (e: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => void;// Handle blur event for input/textarea
10
10
  onFocus?: (e: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => void;// Handle focus event for input/textarea
11
- onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void; // Add onKeyDown
11
+ onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
12
12
  autoFocus?: boolean;
13
- iconLeft?: React.ReactNode;
14
- iconRight?: React.ReactNode | React.ComponentType<any>;
15
13
  multiline?: boolean;
16
14
  maxRows?: number;
17
15
  disabled?: boolean;
@@ -28,8 +26,6 @@ export default function TextField({
28
26
  onFocus,
29
27
  onKeyDown,
30
28
  autoFocus = false, // Accept the autoFocus prop with default value
31
- iconLeft,
32
- iconRight,
33
29
  multiline = false,
34
30
  maxRows = 6,
35
31
  disabled = false,
@@ -60,16 +56,6 @@ export default function TextField({
60
56
  border-gray-300
61
57
  `;
62
58
 
63
- const renderIconRight = () => {
64
- if (React.isValidElement(iconRight)) {
65
- return iconRight;
66
- }
67
- if (typeof iconRight === 'function') {
68
- return React.createElement(iconRight);
69
- }
70
- return null;
71
- };
72
-
73
59
  return (
74
60
  <div className="flex flex-col w-full">
75
61
  {label && (
@@ -78,16 +64,6 @@ export default function TextField({
78
64
  </label>
79
65
  )}
80
66
  <div className="relative">
81
- {iconLeft && (
82
- <span className="absolute inset-y-0 left-0 pl-3 flex items-center">
83
- {iconLeft}
84
- </span>
85
- )}
86
- {iconRight && (
87
- <span className="absolute inset-y-0 right-0 pr-3 flex items-center">
88
- {renderIconRight()}
89
- </span>
90
- )}
91
67
  {multiline ? (
92
68
  <textarea
93
69
  id={id}
@@ -6,18 +6,57 @@ interface UserImageProps {
6
6
  userImgUrl?: string;
7
7
  }
8
8
 
9
+ //read initials from userHandle
10
+ function getInitials(userHandle: string): string {
11
+ const words = userHandle.trim().split(/\s+/);
12
+ return words.slice(0, 2).map(word => word.charAt(0).toUpperCase()).join('');
13
+ }
14
+
15
+ function getColorSeed(userHandle: string): string {
16
+ const words = userHandle.trim().split(/\s+/);
17
+ let letters = words.map(word => word.charAt(0).toLowerCase());
18
+ if (letters.length === 1 && words[0].length >= 2) {
19
+ letters.push(words[0].charAt(1).toLowerCase());
20
+ } else if (letters.length > 2) {
21
+ letters = letters.slice(0, 2);
22
+ } else if (letters.length === 0) {
23
+ letters = ['x', 'x'];
24
+ }
25
+ return letters.join('');
26
+ }
27
+
28
+ function getHash(str: string): number {
29
+ let hash = 0;
30
+ for (let i = 0; i < str.length; i++) {
31
+ hash = str.charCodeAt(i) + ((hash << 5) - hash);
32
+ }
33
+ return hash;
34
+ }
35
+
9
36
  export default function UserImage({
10
37
  userHandle,
11
38
  userImgUrl,
12
39
  }: UserImageProps) {
13
40
 
14
- const defaultInitial = userHandle.charAt(0).toUpperCase();
41
+ const displayInitial = userHandle.charAt(0).toUpperCase() || 'A';
42
+ const seed = getColorSeed(userHandle);
43
+ const hue = Math.abs(getHash(seed)) % 360;
44
+
45
+ // Light mode: lighter pastel
46
+ const lightBg = `hsl(${hue}, 20%, 80%)`;
47
+ // Dark mode: darker variant
48
+ const darkBg = `hsl(${hue}, 20%, 30%)`;
15
49
 
16
50
  return (
17
- <div
18
- className="flex items-center justify-center w-6 h-6 rounded-full overflow-hidden
19
- bg-light-background-accent200 dark:bg-dark-background-accent200
20
- text-light-text-secondary dark:text-dark-text-secondary ">
51
+ <div
52
+ style={{
53
+ '--light-bg': lightBg,
54
+ '--dark-bg': darkBg,
55
+ } as React.CSSProperties}
56
+ className={`flex items-center justify-center w-6 h-6 rounded-full overflow-hidden
57
+ bg-[var(--light-bg)] dark:bg-[var(--dark-bg)]
58
+ text-light-text-secondary dark:text-dark-text-secondary`}
59
+ >
21
60
  {userImgUrl ? (
22
61
  <img
23
62
  src={userImgUrl}
@@ -25,9 +64,9 @@ export default function UserImage({
25
64
  className="w-full h-full object-cover rounded-full"
26
65
  />
27
66
  ) : (
28
- <span className="text-body1">
29
- {defaultInitial}
30
- </span>
67
+ <span className="text-body1 text-light-text-secondary dark:text-dark-text-secondary">
68
+ {displayInitial}
69
+ </span>
31
70
  )}
32
71
  </div>
33
72
  );
@@ -124,9 +124,9 @@ export default function Button(_a) {
124
124
  setIsHovered(true); }} onMouseLeave={function () { if (state !== 'disabled')
125
125
  setIsHovered(false); }} onClick={onClickButton}>
126
126
  {/* Group IconLeft and label in a flex container for left alignment */}
127
- <div className="flex items-center space-x-2">
127
+ <div className="flex items-center">
128
128
  {IconLeft && <IconLeft className={sizeIcon}/>}
129
- <div className="whitespace-nowrap overflow-hidden truncate">{label}</div>
129
+ <div className="whitespace-nowrap overflow-hidden truncate px-2">{label}</div>
130
130
  </div>
131
131
  {IconRight && (<div onClick={onClickActionIcon} className="cursor-pointer">
132
132
  <IconRight className={sizeIcon}/>
@@ -8,8 +8,6 @@ interface TextFieldProps {
8
8
  onFocus?: (e: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
9
9
  onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
10
10
  autoFocus?: boolean;
11
- iconLeft?: React.ReactNode;
12
- iconRight?: React.ReactNode | React.ComponentType<any>;
13
11
  multiline?: boolean;
14
12
  maxRows?: number;
15
13
  disabled?: boolean;
@@ -17,5 +15,5 @@ interface TextFieldProps {
17
15
  size?: 'large' | 'medium' | 'small';
18
16
  }
19
17
  export default function TextField({ id, label, value, onChange, onBlur, onFocus, onKeyDown, autoFocus, // Accept the autoFocus prop with default value
20
- iconLeft, iconRight, multiline, maxRows, disabled, error, size, }: TextFieldProps): React.JSX.Element;
18
+ multiline, maxRows, disabled, error, size, }: TextFieldProps): React.JSX.Element;
21
19
  export {};
@@ -2,7 +2,8 @@
2
2
  import React, { useState } from 'react';
3
3
  export default function TextField(_a) {
4
4
  var id = _a.id, label = _a.label, value = _a.value, onChange = _a.onChange, onBlur = _a.onBlur, onFocus = _a.onFocus, onKeyDown = _a.onKeyDown, _b = _a.autoFocus, autoFocus = _b === void 0 ? false : _b, // Accept the autoFocus prop with default value
5
- iconLeft = _a.iconLeft, iconRight = _a.iconRight, _c = _a.multiline, multiline = _c === void 0 ? false : _c, _d = _a.maxRows, maxRows = _d === void 0 ? 6 : _d, _e = _a.disabled, disabled = _e === void 0 ? false : _e, _f = _a.error, error = _f === void 0 ? false : _f, _g = _a.size, size = _g === void 0 ? 'medium' : _g;
5
+ _c = _a.multiline, // Accept the autoFocus prop with default value
6
+ multiline = _c === void 0 ? false : _c, _d = _a.maxRows, maxRows = _d === void 0 ? 6 : _d, _e = _a.disabled, disabled = _e === void 0 ? false : _e, _f = _a.error, error = _f === void 0 ? false : _f, _g = _a.size, size = _g === void 0 ? 'medium' : _g;
6
7
  var _h = useState(false), isFocused = _h[0], setIsFocused = _h[1];
7
8
  // Define classes for size: text size and padding
8
9
  var sizeClasses = {
@@ -14,26 +15,11 @@ export default function TextField(_a) {
14
15
  var bgColor = 'bg-light-background-default dark:bg-dark-background-default transition-colors duration-200 ease-in-out';
15
16
  var borderColor = 'border-light-outlinedBorder-active dark:border-dark-outlinedBorder-active';
16
17
  var containerClasses = "\n ".concat(bgColor, "\n ").concat(borderColor, "\n ").concat(baseClasses, "\n ").concat(sizeClasses, "\n ").concat(disabled ? 'bg-gray-200 cursor-not-allowed' : '', "\n ").concat(error ? 'border-red-500 focus:ring-red-500' : '', "\n ").concat(isFocused ? 'focus:border-light-accent-main focus:dark:border-dark-accent-main outline-none' : '', "\n ").concat(!disabled && !error ? 'hover:border-light-outlinedBorder-hover' : '', "\n border-gray-300\n ");
17
- var renderIconRight = function () {
18
- if (React.isValidElement(iconRight)) {
19
- return iconRight;
20
- }
21
- if (typeof iconRight === 'function') {
22
- return React.createElement(iconRight);
23
- }
24
- return null;
25
- };
26
18
  return (<div className="flex flex-col w-full">
27
19
  {label && (<label htmlFor={id} className="mb-1 text-body2 text-light-text-secondary dark:text-dark-text-secondary">
28
20
  {label}
29
21
  </label>)}
30
22
  <div className="relative">
31
- {iconLeft && (<span className="absolute inset-y-0 left-0 pl-3 flex items-center">
32
- {iconLeft}
33
- </span>)}
34
- {iconRight && (<span className="absolute inset-y-0 right-0 pr-3 flex items-center">
35
- {renderIconRight()}
36
- </span>)}
37
23
  {multiline ? (<textarea id={id} rows={maxRows} className={containerClasses} value={value} onChange={onChange} onFocus={function (e) {
38
24
  setIsFocused(true);
39
25
  if (onFocus)
package/dist/output.css CHANGED
@@ -549,16 +549,6 @@ video {
549
549
  left: 0px;
550
550
  right: 0px;
551
551
  }
552
- .inset-y-0 {
553
- top: 0px;
554
- bottom: 0px;
555
- }
556
- .left-0 {
557
- left: 0px;
558
- }
559
- .right-0 {
560
- right: 0px;
561
- }
562
552
  .top-4 {
563
553
  top: 1rem;
564
554
  }
@@ -888,12 +878,6 @@ video {
888
878
  padding-top: 3px;
889
879
  padding-bottom: 3px;
890
880
  }
891
- .pl-3 {
892
- padding-left: 0.75rem;
893
- }
894
- .pr-3 {
895
- padding-right: 0.75rem;
896
- }
897
881
  .text-center {
898
882
  text-align: center;
899
883
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "oneslash-design-system",
3
3
  "description": "A design system for the Oneslash projects",
4
- "version": "1.1.29",
4
+ "version": "1.1.31",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",