Skip to content

Commit d02ea4b

Browse files
committed
fix: Auto-arrange title, searchbar, buttons responsively
1 parent d426cd6 commit d02ea4b

File tree

3 files changed

+113
-69
lines changed

3 files changed

+113
-69
lines changed

src/components/ButtonGroup.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ export const ButtonGroup: React.FC<ButtonGroupProps> = ({
6262
};
6363

6464
return (
65-
<div style={{ display: "flex", gap: "0.5rem", flexShrink: 0 }}>
65+
<div style={{ display: "flex", gap: "0.5rem", flexWrap: "wrap", alignItems: "center" }}>
6666
{buttons.map((button) => (
67-
<div key={button.id} style={{ position: 'relative' }}>
67+
<div key={button.id} style={{ position: 'relative', flexShrink: 0 }}>
6868
<Button
6969
icon={button.icon}
7070
text={button.text}

src/components/MultiLevelTable.tsx

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -704,43 +704,41 @@ export const MultiLevelTable: React.FC<MultiLevelTableProps> = ({
704704
<div className="table-wrapper">
705705
{showSearchBar && (
706706
<div className="search-bar-container">
707-
<div className="search-bar-left">
708-
{tableTitle && (
709-
<div className="table-title-container">
710-
<h2 style={componentStyles.title.table}>
711-
{tableTitle}
712-
</h2>
713-
{tableSubtitle && (
714-
<p
715-
className="table-subtitle"
716-
style={{
717-
color: mergedTheme.colors?.textColor || colors.textSecondary,
718-
}}
719-
>
720-
{tableSubtitle}
721-
</p>
722-
)}
723-
</div>
724-
)}
725-
<div className="search-input-container">
726-
<span className="search-input-icon">
727-
<SearchIcon width={24} height={24} />
728-
</span>
729-
<input
730-
className="search-input"
731-
type="text"
732-
placeholder="Search"
733-
value={searchTerm}
734-
onChange={e => onSearchChange?.(e.target.value)}
735-
style={{
736-
borderColor: mergedTheme.table?.cell?.borderColor || colors.searchBorder,
737-
backgroundColor: mergedTheme.colors?.background || colors.backgroundWhite,
738-
color: mergedTheme.colors?.textColor || colors.textPrimary,
739-
}}
740-
/>
707+
{tableTitle && (
708+
<div className="table-title-container">
709+
<h2 style={componentStyles.title.table}>
710+
{tableTitle}
711+
</h2>
712+
{tableSubtitle && (
713+
<p
714+
className="table-subtitle"
715+
style={{
716+
color: mergedTheme.colors?.textColor || colors.textSecondary,
717+
}}
718+
>
719+
{tableSubtitle}
720+
</p>
721+
)}
741722
</div>
723+
)}
724+
<div className="search-input-container">
725+
<span className="search-input-icon">
726+
<SearchIcon width={24} height={24} />
727+
</span>
728+
<input
729+
className="search-input"
730+
type="text"
731+
placeholder="Search"
732+
value={searchTerm}
733+
onChange={e => onSearchChange?.(e.target.value)}
734+
style={{
735+
borderColor: mergedTheme.table?.cell?.borderColor || colors.searchBorder,
736+
backgroundColor: mergedTheme.colors?.background || colors.backgroundWhite,
737+
color: mergedTheme.colors?.textColor || colors.textPrimary,
738+
}}
739+
/>
742740
</div>
743-
<div className="search-bar-right">
741+
<div className="action-buttons-container">
744742
{renderActionButtons()}
745743
</div>
746744
</div>

src/styles/MultiLevelTable.css

Lines changed: 78 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,13 @@
252252
align-items: center;
253253
padding: 1rem;
254254
gap: 1rem;
255-
flex-wrap: nowrap; /* Prevent wrapping on larger screens */
255+
flex-wrap: wrap; /* Allow natural wrapping */
256256
}
257257

258-
.search-bar-left {
259-
display: flex;
260-
align-items: center;
261-
gap: 1rem;
262-
flex: 1;
263-
min-width: 0; /* Allow shrinking */
264-
}
265-
266-
.search-bar-right {
258+
.action-buttons-container {
267259
display: flex;
268260
gap: 0.5rem;
269-
flex-shrink: 0; /* Prevent shrinking */
270-
align-items: center;
261+
flex-wrap: wrap; /* Allow buttons to wrap */
271262
}
272263

273264
.table-title-container {
@@ -338,14 +329,12 @@
338329
gap: 1rem;
339330
}
340331

341-
.search-bar-left {
332+
.action-buttons-container {
342333
width: 100%;
343-
}
344-
345-
.search-bar-right {
346-
width: 100%;
347-
justify-content: space-between;
348-
gap: 1rem;
334+
display: flex;
335+
flex-wrap: wrap;
336+
gap: 0.5rem;
337+
justify-content: flex-start;
349338
}
350339

351340
.search-input-container {
@@ -409,11 +398,7 @@
409398
gap: 0.75rem;
410399
}
411400

412-
.search-bar-left {
413-
width: 100%;
414-
}
415-
416-
.search-bar-right {
401+
.action-buttons-container {
417402
width: 100%;
418403
justify-content: space-between;
419404
gap: 0.5rem;
@@ -455,22 +440,84 @@
455440
align-items: center;
456441
}
457442

458-
/* let the children of .search-bar-left take part in the grid */
459-
.search-bar-left {
460-
display: contents; /* no box of its own */
461-
}
462-
463443
/* name each piece */
464444
.table-title-container { grid-area: title; }
465445
.search-input-container { grid-area: search; }
466446

467447
/* push buttons to the right */
468-
.search-bar-right {
448+
.action-buttons-container {
469449
grid-area: buttons;
470450
justify-self: end; /* align right edge */
471451
}
472452
}
473453

454+
/* ≤ 700px – 3-line layout for 3+ buttons */
455+
@media (max-width: 700px) {
456+
.search-bar-container {
457+
display: flex;
458+
flex-direction: column;
459+
align-items: stretch;
460+
gap: 1rem;
461+
}
462+
463+
.action-buttons-container {
464+
width: 100%;
465+
display: flex;
466+
flex-wrap: wrap;
467+
gap: 0.5rem;
468+
justify-content: flex-start;
469+
}
470+
471+
/* Allow search bar and buttons to share the same line when possible */
472+
.search-input-container {
473+
flex: 1;
474+
min-width: 200px;
475+
}
476+
}
477+
478+
/* ≤ 527px – 3-line layout for 2 buttons */
479+
@media (max-width: 527px) {
480+
.search-bar-container {
481+
display: flex;
482+
flex-direction: column;
483+
align-items: stretch;
484+
gap: 1rem;
485+
}
486+
487+
.action-buttons-container {
488+
width: 100%;
489+
display: flex;
490+
flex-wrap: wrap;
491+
gap: 0.5rem;
492+
justify-content: flex-start;
493+
}
494+
}
495+
496+
/* ≤ 489px – 4-line layout with 2x2 button grid for 3 buttons */
497+
@media (max-width: 489px) {
498+
.search-bar-container {
499+
display: flex;
500+
flex-direction: column;
501+
align-items: stretch;
502+
gap: 1rem;
503+
}
504+
505+
.action-buttons-container {
506+
width: 100%;
507+
display: flex;
508+
flex-wrap: wrap;
509+
gap: 0.5rem;
510+
flex-direction: column;
511+
justify-content: flex-start;
512+
}
513+
514+
/* Ensure buttons maintain their minimum width and don't break content */
515+
.action-buttons-container > * {
516+
min-width: 120px;
517+
flex-shrink: 0;
518+
}
519+
}
520+
474521
/* Large desktop breakpoint */
475522
@media (min-width: 1025px) {
476523
.search-bar-container {
@@ -485,8 +532,7 @@
485532
margin-bottom: 0.5rem;
486533
}
487534

488-
.search-bar-left,
489-
.search-bar-right {
535+
.action-buttons-container {
490536
width: 100%;
491537
}
492538
}

0 commit comments

Comments
 (0)