@mirror-physics/fractal-ui 0.2.0-next.57 → 0.2.0-next.58

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.cjs CHANGED
@@ -1158,6 +1158,7 @@ function Dropdown({
1158
1158
  triggerLabel = "Options",
1159
1159
  direction = "down",
1160
1160
  align = "left",
1161
+ triggerOrientation = "horizontal",
1161
1162
  triggerContent,
1162
1163
  label,
1163
1164
  iconOnly = false,
@@ -1181,41 +1182,59 @@ function Dropdown({
1181
1182
  const selectableItems = visibleItems.filter((i) => i.kind !== "header");
1182
1183
  const selected = items.find((i) => i.value === selectedValue && i.kind !== "header") ?? selectableItems[0] ?? visibleItems[0];
1183
1184
  const isUp = direction === "up";
1184
- const ChevronIcon = isUp ? import_fractal_icons7.ChevronUp : import_fractal_icons7.ChevronDown;
1185
+ const isHorizontalDirection = direction === "left" || direction === "right";
1186
+ const ChevronIcon = direction === "up" ? import_fractal_icons7.ChevronUp : direction === "left" ? import_fractal_icons7.ChevronLeft : direction === "right" ? import_fractal_icons7.ChevronRight : import_fractal_icons7.ChevronDown;
1185
1187
  React9.useLayoutEffect(() => {
1186
1188
  if (!open || !triggerRef.current || !panelRef.current) return;
1187
1189
  const triggerRect = triggerRef.current.getBoundingClientRect();
1188
1190
  const panelRect = panelRef.current.getBoundingClientRect();
1189
1191
  const vw = window.innerWidth;
1190
1192
  const vh = window.innerHeight;
1191
- const spaceBelow = vh - triggerRect.bottom - MARGIN;
1192
- const spaceAbove = triggerRect.top - MARGIN;
1193
- let placeAbove = isUp;
1194
- if (placeAbove && panelRect.height > spaceAbove && spaceBelow > spaceAbove) {
1195
- placeAbove = false;
1196
- } else if (!placeAbove && panelRect.height > spaceBelow && spaceAbove > spaceBelow) {
1197
- placeAbove = true;
1198
- }
1199
- const top = placeAbove ? -(panelRect.height + MARGIN) : triggerRect.height + MARGIN;
1193
+ let top;
1200
1194
  let left;
1201
1195
  let right;
1202
- if (align === "right") {
1203
- right = 0;
1204
- const panelLeft = triggerRect.right - panelRect.width;
1205
- if (panelLeft < 0) {
1206
- right = void 0;
1207
- left = 0;
1196
+ if (isHorizontalDirection) {
1197
+ const spaceRight = vw - triggerRect.right - MARGIN;
1198
+ const spaceLeft = triggerRect.left - MARGIN;
1199
+ let placeRight = direction === "right";
1200
+ if (placeRight && panelRect.width > spaceRight && spaceLeft > spaceRight) {
1201
+ placeRight = false;
1202
+ } else if (!placeRight && panelRect.width > spaceLeft && spaceRight > spaceLeft) {
1203
+ placeRight = true;
1208
1204
  }
1205
+ left = placeRight ? triggerRect.width + MARGIN : -(panelRect.width + MARGIN);
1206
+ top = 0;
1207
+ const panelBottom = triggerRect.top + panelRect.height;
1208
+ if (panelBottom > vh - MARGIN) top -= panelBottom - (vh - MARGIN);
1209
+ if (triggerRect.top + top < MARGIN) top += MARGIN - (triggerRect.top + top);
1209
1210
  } else {
1210
- left = 0;
1211
- const panelRight = triggerRect.left + panelRect.width;
1212
- if (panelRight > vw) {
1213
- left = void 0;
1211
+ const spaceBelow = vh - triggerRect.bottom - MARGIN;
1212
+ const spaceAbove = triggerRect.top - MARGIN;
1213
+ let placeAbove = isUp;
1214
+ if (placeAbove && panelRect.height > spaceAbove && spaceBelow > spaceAbove) {
1215
+ placeAbove = false;
1216
+ } else if (!placeAbove && panelRect.height > spaceBelow && spaceAbove > spaceBelow) {
1217
+ placeAbove = true;
1218
+ }
1219
+ top = placeAbove ? -(panelRect.height + MARGIN) : triggerRect.height + MARGIN;
1220
+ if (align === "right") {
1214
1221
  right = 0;
1222
+ const panelLeft = triggerRect.right - panelRect.width;
1223
+ if (panelLeft < 0) {
1224
+ right = void 0;
1225
+ left = 0;
1226
+ }
1227
+ } else {
1228
+ left = 0;
1229
+ const panelRight = triggerRect.left + panelRect.width;
1230
+ if (panelRight > vw) {
1231
+ left = void 0;
1232
+ right = 0;
1233
+ }
1215
1234
  }
1216
1235
  }
1217
1236
  setPanelStyle({ top, left, right });
1218
- }, [open, isUp, align]);
1237
+ }, [open, direction, isHorizontalDirection, isUp, align]);
1219
1238
  React9.useEffect(() => {
1220
1239
  if (!open) return;
1221
1240
  const handleClickOutside = (e) => {
@@ -1241,6 +1260,7 @@ function Dropdown({
1241
1260
  "fractal-dropdown-trigger",
1242
1261
  `fractal-dropdown-trigger--${size}`,
1243
1262
  `fractal-dropdown-trigger--${triggerVariant}`,
1263
+ `fractal-dropdown-trigger--${triggerOrientation}`,
1244
1264
  iconOnly && "fractal-dropdown-trigger--icon-only",
1245
1265
  triggerClassName
1246
1266
  ),