@designbasekorea/figma-ui 0.1.76 → 0.1.78

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.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { useRef, useEffect, useState, createContext, useContext, useCallback } from 'react';
2
- import { HeartFilledIcon, CoffeeFilledIcon, AppWindowIcon, YoutubeIcon, InstagramIcon, FigmaIcon, MailIcon, ExternalLinkIcon, MoreHorizontalIcon, CloseIcon, CircleCheckFilledIcon, ResizableIcon, GripVerticalIcon } from '@designbasekorea/icons';
2
+ import { HeartFilledIcon, CoffeeFilledIcon, ChevronDownIcon, AppWindowIcon, YoutubeIcon, InstagramIcon, FigmaIcon, MailIcon, ExternalLinkIcon, MoreHorizontalIcon, CloseIcon, CircleCheckFilledIcon, ResizableIcon, GripVerticalIcon } from '@designbasekorea/icons';
3
3
  import { Button, SplitView, Toggle, Spinner, Badge, SegmentControl, Logo, ToastContainer, Toast, Input, Modal, Progressbar } from '@designbasekorea/ui';
4
4
  export * from '@designbasekorea/ui';
5
5
 
@@ -101,16 +101,39 @@ const FigmaHeader = ({ children, actions = [], searchBar, sticky = true, classNa
101
101
  };
102
102
  FigmaHeader.displayName = 'FigmaHeader';
103
103
 
104
- const FigmaSection = ({ title, dataCategory, iconButton, children, marginBottom, isEnabled = true, onToggle, className, enableScrollNavigation = false, headerHeight = 94, onActiveSectionChange, t }) => {
104
+ const FigmaSection = ({ title, dataCategory, iconButton, children, marginBottom, isEnabled = true, onToggle, className, enableScrollNavigation = false, headerHeight = 94, onActiveSectionChange, t, collapsible = false, defaultCollapsed = false, onCollapseChange }) => {
105
105
  const sectionRef = useRef(null);
106
+ const contentRef = useRef(null);
107
+ const [isCollapsed, setIsCollapsed] = React.useState(defaultCollapsed);
106
108
  const sectionStyle = marginBottom ? { marginBottom: `${marginBottom}px` } : {};
107
109
  const classes = [
108
110
  'designbase-figma-section',
109
111
  !isEnabled && 'designbase-figma-section--disabled',
112
+ collapsible && 'designbase-figma-section--collapsible',
113
+ isCollapsed && collapsible && 'designbase-figma-section--collapsed',
110
114
  className,
111
115
  ]
112
116
  .filter(Boolean)
113
117
  .join(' ');
118
+ const handleHeaderClick = () => {
119
+ if (collapsible) {
120
+ const newCollapsed = !isCollapsed;
121
+ setIsCollapsed(newCollapsed);
122
+ if (onCollapseChange) {
123
+ onCollapseChange(newCollapsed, dataCategory);
124
+ }
125
+ }
126
+ };
127
+ React.useEffect(() => {
128
+ if (collapsible && contentRef.current) {
129
+ if (!isCollapsed) {
130
+ contentRef.current.style.maxHeight = `${contentRef.current.scrollHeight}px`;
131
+ }
132
+ else {
133
+ contentRef.current.style.maxHeight = '0px';
134
+ }
135
+ }
136
+ }, [isCollapsed, collapsible]);
114
137
  useEffect(() => {
115
138
  if (!enableScrollNavigation || !onActiveSectionChange || !sectionRef.current)
116
139
  return;
@@ -132,12 +155,14 @@ const FigmaSection = ({ title, dataCategory, iconButton, children, marginBottom,
132
155
  };
133
156
  }, [enableScrollNavigation, dataCategory, headerHeight, onActiveSectionChange]);
134
157
  return (React.createElement("section", { ref: sectionRef, className: classes, ...(dataCategory ? { 'data-category': dataCategory } : {}), style: sectionStyle },
135
- title && (React.createElement("div", { className: "designbase-figma-section__header" },
158
+ title && (React.createElement("div", { className: "designbase-figma-section__header", onClick: collapsible ? handleHeaderClick : undefined, style: collapsible ? { cursor: 'pointer' } : undefined },
136
159
  React.createElement("h2", { className: "designbase-figma-section__title" }, resolveText(t, title)),
137
160
  React.createElement("div", { className: "designbase-figma-section__controls" },
138
161
  iconButton,
162
+ collapsible && (React.createElement("span", { className: `designbase-figma-section__collapse-icon ${isCollapsed ? 'designbase-figma-section__collapse-icon--collapsed' : ''}` },
163
+ React.createElement(ChevronDownIcon, { size: 16 }))),
139
164
  onToggle && (React.createElement(Toggle, { checked: isEnabled, onChange: () => onToggle(dataCategory), size: "s" }))))),
140
- React.createElement("div", { className: `designbase-figma-section__content ${!isEnabled ? 'designbase-figma-section__content--hidden' : ''}` }, children)));
165
+ React.createElement("div", { ref: contentRef, className: `designbase-figma-section__content ${!isEnabled ? 'designbase-figma-section__content--hidden' : ''} ${isCollapsed && collapsible ? 'designbase-figma-section__content--collapsed' : ''}` }, children)));
141
166
  };
142
167
  FigmaSection.displayName = 'FigmaSection';
143
168
  const scrollToSection = (category, headerHeight = 94) => {