@noya-app/noya-designsystem 0.1.8 → 0.1.10

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.mjs CHANGED
@@ -114,94 +114,104 @@ var Tooltip = memo2(function Tooltip2({ children, content }) {
114
114
  });
115
115
 
116
116
  // src/components/Button.tsx
117
- var ButtonElement = styled4.button(({ theme, active, disabled, variant, size: size2, flex }) => ({
118
- ...size2 === "large" ? theme.textStyles.heading4 : theme.textStyles.small,
119
- textDecoration: "none",
120
- lineHeight: "1",
121
- flex: flex ?? "0 0 auto",
122
- position: "relative",
123
- border: "0",
124
- outline: "none",
125
- WebkitAppRegion: "no-drag",
126
- userSelect: "none",
127
- minWidth: variant === "normal" ? "31px" : void 0,
128
- textAlign: "left",
129
- borderRadius: "4px",
130
- paddingTop: variant === "none" ? "0px" : "4px",
131
- paddingRight: variant === "none" ? "0px" : variant === "thin" ? "1px" : "8px",
132
- paddingBottom: variant === "none" ? "0px" : "4px",
133
- paddingLeft: variant === "none" ? "0px" : variant === "thin" ? "1px" : "8px",
134
- ...size2 === "large" && {
135
- paddingTop: "12px",
136
- paddingRight: "16px",
137
- paddingBottom: "12px",
138
- paddingLeft: "16px"
139
- },
140
- background: active ? theme.colors.primary : variant === "primaryGradient" ? `linear-gradient(90deg, ${theme.colors.primary}, ${theme.colors.primaryLight})` : variant === "none" || variant === "thin" ? "transparent" : theme.colors.inputBackground,
141
- color: active ? "white" : theme.colors.text,
142
- opacity: disabled ? 0.25 : 1,
143
- "&:focus": {
144
- boxShadow: `0 0 0 1px ${theme.colors.sidebar.background}, 0 0 0 3px ${theme.colors.primary}`
145
- },
146
- "&:hover": {
147
- background: variant === "primaryGradient" || active ? theme.colors.primaryLight : theme.colors.inputBackgroundLight
148
- },
149
- "&:active": {
150
- background: variant === "primaryGradient" ? theme.colors.primary : theme.colors.activeBackground
151
- },
152
- ...variant === "primary" && {
153
- background: theme.colors.primary,
154
- color: "white",
155
- "&:hover": {
156
- background: theme.colors.primaryLight
117
+ var ButtonElement = styled4.button(
118
+ ({
119
+ theme,
120
+ active,
121
+ disabled,
122
+ variant,
123
+ size: size2,
124
+ flex,
125
+ defaultBackground = theme.colors.inputBackground
126
+ }) => ({
127
+ ...size2 === "large" ? theme.textStyles.heading4 : theme.textStyles.small,
128
+ textDecoration: "none",
129
+ lineHeight: "1",
130
+ flex: flex ?? "0 0 auto",
131
+ position: "relative",
132
+ border: "0",
133
+ outline: "none",
134
+ WebkitAppRegion: "no-drag",
135
+ userSelect: "none",
136
+ minWidth: variant === "normal" ? "31px" : void 0,
137
+ textAlign: "left",
138
+ borderRadius: "4px",
139
+ paddingTop: variant === "none" ? "0px" : "4px",
140
+ paddingRight: variant === "none" ? "0px" : variant === "thin" ? "1px" : "8px",
141
+ paddingBottom: variant === "none" ? "0px" : "4px",
142
+ paddingLeft: variant === "none" ? "0px" : variant === "thin" ? "1px" : "8px",
143
+ ...size2 === "large" && {
144
+ paddingTop: "12px",
145
+ paddingRight: "16px",
146
+ paddingBottom: "12px",
147
+ paddingLeft: "16px"
157
148
  },
158
- "&:active": {
159
- background: theme.colors.primary
160
- }
161
- },
162
- ...variant === "secondary" && {
163
- background: theme.colors.secondary,
164
- color: "white",
165
- "&:hover": {
166
- background: theme.colors.secondaryLight
149
+ background: active ? theme.colors.primary : variant === "primaryGradient" ? `linear-gradient(90deg, ${theme.colors.primary}, ${theme.colors.primaryLight})` : variant === "none" || variant === "thin" ? "transparent" : defaultBackground,
150
+ color: active ? "white" : theme.colors.text,
151
+ opacity: disabled ? 0.25 : 1,
152
+ "&:focus": {
153
+ boxShadow: `0 0 0 1px ${theme.colors.sidebar.background}, 0 0 0 3px ${theme.colors.primary}`
167
154
  },
168
- "&:active": {
169
- background: theme.colors.secondary
170
- }
171
- },
172
- ...variant === "secondaryBright" && {
173
- background: "#0ab557",
174
- color: "white",
175
155
  "&:hover": {
176
- opacity: 0.8
156
+ background: variant === "primaryGradient" || active ? theme.colors.primaryLight : theme.colors.inputBackgroundLight
177
157
  },
178
158
  "&:active": {
179
- opacity: 0.9
180
- }
181
- },
182
- ...variant === "white" && {
183
- background: "white",
184
- "&:hover": {
185
- opacity: 0.8
159
+ background: variant === "primaryGradient" || active ? theme.colors.primary : theme.colors.activeBackground
186
160
  },
187
- "&:active": {
188
- opacity: 0.9
161
+ ...variant === "primary" && {
162
+ background: theme.colors.primary,
163
+ color: "white",
164
+ "&:hover": {
165
+ background: theme.colors.primaryLight
166
+ },
167
+ "&:active": {
168
+ background: theme.colors.primary
169
+ }
170
+ },
171
+ ...variant === "secondary" && {
172
+ background: theme.colors.secondary,
173
+ color: "white",
174
+ "&:hover": {
175
+ background: theme.colors.secondaryLight
176
+ },
177
+ "&:active": {
178
+ background: theme.colors.secondary
179
+ }
180
+ },
181
+ ...variant === "secondaryBright" && {
182
+ background: "#0ab557",
183
+ color: "white",
184
+ "&:hover": {
185
+ opacity: 0.8
186
+ },
187
+ "&:active": {
188
+ opacity: 0.9
189
+ }
190
+ },
191
+ ...variant === "white" && {
192
+ background: "white",
193
+ "&:hover": {
194
+ opacity: 0.8
195
+ },
196
+ "&:active": {
197
+ opacity: 0.9
198
+ }
199
+ },
200
+ ...variant === "floating" && {
201
+ background: "white",
202
+ color: theme.colors.text,
203
+ boxShadow: "0 1px 2px rgba(0, 0, 0, 0.1)",
204
+ fontSize: "12px",
205
+ padding: "0px 4px"
206
+ },
207
+ display: "flex",
208
+ alignItems: "center",
209
+ justifyContent: "center",
210
+ "& *": {
211
+ pointerEvents: "none"
189
212
  }
190
- },
191
- ...variant === "floating" && {
192
- background: "white",
193
- color: theme.colors.text,
194
- boxShadow: "0 1px 2px rgba(0, 0, 0, 0.1)",
195
- fontSize: "12px",
196
- padding: "0px 4px"
197
- },
198
- display: "flex",
199
- alignItems: "center",
200
- justifyContent: "center",
201
- "& *": {
202
- pointerEvents: "none"
203
- }
204
- }));
213
+ })
214
+ );
205
215
  var ButtonContent = styled4.span(({ theme }) => ({
206
216
  // Line height of small text - maybe figure out better way to ensure
207
217
  // icons don't have a smaller height
@@ -225,6 +235,7 @@ var Button = forwardRef(function Button2({
225
235
  variant = "normal",
226
236
  size: size2 = "normal",
227
237
  contentStyle,
238
+ defaultBackground,
228
239
  onClick,
229
240
  children,
230
241
  ...rest
@@ -243,6 +254,7 @@ var Button = forwardRef(function Button2({
243
254
  disabled,
244
255
  variant,
245
256
  size: size2,
257
+ defaultBackground,
246
258
  onClick,
247
259
  onDoubleClick: useCallback((event) => {
248
260
  event.stopPropagation();
@@ -703,6 +715,85 @@ import { useEffect as useEffect6, useState as useState8 } from "react";
703
715
  import { decodeQueryParameters } from "@noya-app/noya-utils";
704
716
  import { useEffect as useEffect7, useState as useState9 } from "react";
705
717
 
718
+ // ../emitter/src/index.ts
719
+ var Emitter = class {
720
+ constructor(options = {}) {
721
+ this.bufferEventsIfNoListeners = options.bufferEventsIfNoListeners ?? false;
722
+ }
723
+ bufferEventsIfNoListeners;
724
+ listeners = [];
725
+ addListener = (f, options = {}) => {
726
+ if (options.once) {
727
+ const handler = (...args) => {
728
+ this.removeListener(handler);
729
+ return f(...args);
730
+ };
731
+ this.listeners.push(handler);
732
+ } else {
733
+ this.listeners.push(f);
734
+ }
735
+ if (this.bufferedEvents.length > 0) {
736
+ const eventsToEmit = this.bufferedEvents;
737
+ this.bufferedEvents = [];
738
+ eventsToEmit.forEach((event) => {
739
+ this.emit(...event);
740
+ });
741
+ }
742
+ return () => this.removeListener(f);
743
+ };
744
+ removeListener = (f) => {
745
+ const index = this.listeners.indexOf(f);
746
+ if (index === -1)
747
+ return;
748
+ this.listeners.splice(index, 1);
749
+ };
750
+ emit = (...args) => {
751
+ if (this.bufferEventsIfNoListeners && this.listeners.length === 0) {
752
+ this.bufferedEvents.push(args);
753
+ return;
754
+ }
755
+ this.listeners.forEach((l) => l(...args));
756
+ };
757
+ bufferedEvents = [];
758
+ };
759
+
760
+ // ../noya-react-utils/src/utils/ClientStorage.ts
761
+ var ClientStorage = class {
762
+ getItem(storageKey) {
763
+ if (typeof localStorage === "undefined") {
764
+ return null;
765
+ }
766
+ return localStorage.getItem(storageKey);
767
+ }
768
+ setItem(storageKey, value) {
769
+ if (typeof localStorage === "undefined") {
770
+ return;
771
+ }
772
+ if (value === null) {
773
+ localStorage.removeItem(storageKey);
774
+ } else {
775
+ localStorage.setItem(storageKey, value);
776
+ }
777
+ this.emitter.emit(storageKey, value);
778
+ }
779
+ emitter = new Emitter();
780
+ _isListening = false;
781
+ addListener(storageKey, listener) {
782
+ if (!this._isListening && typeof window !== "undefined") {
783
+ this._isListening = true;
784
+ window.addEventListener("storage", (event) => {
785
+ this.emitter.emit(event.key, event.newValue);
786
+ });
787
+ }
788
+ return this.emitter.addListener((key, value) => {
789
+ if (key === storageKey) {
790
+ listener(value);
791
+ }
792
+ });
793
+ }
794
+ };
795
+ var clientStorage = new ClientStorage();
796
+
706
797
  // ../noya-react-utils/src/utils/assignRef.ts
707
798
  function assignRef(ref, value) {
708
799
  if (typeof ref === "function") {
@@ -796,7 +887,7 @@ var styles = {
796
887
  separatorStyle: ({ theme }) => ({
797
888
  height: "1px",
798
889
  backgroundColor: theme.colors.divider,
799
- margin: "4px 8px"
890
+ margin: "4px -4px"
800
891
  }),
801
892
  itemStyle: ({
802
893
  theme,
@@ -809,7 +900,7 @@ var styles = {
809
900
  userSelect: "none",
810
901
  cursor: "pointer",
811
902
  borderRadius: "3px",
812
- padding: "4px 8px",
903
+ padding: "6px 8px",
813
904
  ...disabled && {
814
905
  color: theme.colors.textDisabled
815
906
  },
@@ -940,7 +1031,16 @@ var DropdownMenuItem = memo7(function ContextMenuItem({
940
1031
  }
941
1032
  const element = /* @__PURE__ */ React12.createElement(ItemElement, { disabled, onSelect: handleSelectItem }, indented && /* @__PURE__ */ React12.createElement(Spacer.Horizontal, { size: CHECKBOX_WIDTH - CHECKBOX_RIGHT_INSET }), icon && /* @__PURE__ */ React12.createElement(React12.Fragment, null, icon, /* @__PURE__ */ React12.createElement(Spacer.Horizontal, { size: 8 })), children, shortcut && /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement(Spacer.Horizontal, null), /* @__PURE__ */ React12.createElement(Spacer.Horizontal, { size: 24 }), /* @__PURE__ */ React12.createElement(KeyboardShortcut, { shortcut })), items && items.length > 0 && /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement(Spacer.Horizontal, null), /* @__PURE__ */ React12.createElement(Spacer.Horizontal, { size: 16 }), /* @__PURE__ */ React12.createElement(ChevronRightIcon, null)));
942
1033
  if (items && items.length > 0) {
943
- return /* @__PURE__ */ React12.createElement(DropdownMenuRoot, { isNested: true, items, onSelect }, element);
1034
+ return /* @__PURE__ */ React12.createElement(
1035
+ DropdownMenuRoot,
1036
+ {
1037
+ isNested: true,
1038
+ items,
1039
+ onSelect,
1040
+ alignOffset: -5
1041
+ },
1042
+ element
1043
+ );
944
1044
  } else {
945
1045
  return element;
946
1046
  }
@@ -955,7 +1055,12 @@ var DropdownMenuRoot = forwardRef4(function DropdownMenuRoot2({
955
1055
  shouldBindKeyboardShortcuts,
956
1056
  onOpenChange,
957
1057
  open,
958
- onCloseAutoFocus
1058
+ onCloseAutoFocus,
1059
+ side,
1060
+ sideOffset = 4,
1061
+ align,
1062
+ alignOffset,
1063
+ collisionPadding = 8
959
1064
  }, forwardedRef) {
960
1065
  const hasCheckedItem = items.some(
961
1066
  (item) => item !== SEPARATOR_ITEM && item.checked
@@ -972,9 +1077,12 @@ var DropdownMenuRoot = forwardRef4(function DropdownMenuRoot2({
972
1077
  return /* @__PURE__ */ React12.createElement(RootComponent, { onOpenChange, open }, /* @__PURE__ */ React12.createElement(TriggerComponent, { ref: forwardedRef, asChild: true }, children), /* @__PURE__ */ React12.createElement(RadixDropdownMenu.Portal, null, /* @__PURE__ */ React12.createElement(
973
1078
  ContentComponent,
974
1079
  {
975
- sideOffset: 4,
1080
+ side,
1081
+ sideOffset,
1082
+ align,
1083
+ alignOffset,
976
1084
  style: contentStyle,
977
- collisionPadding: 8,
1085
+ collisionPadding,
978
1086
  ...{ onCloseAutoFocus }
979
1087
  },
980
1088
  items.map(