Skip to content

Commit 69c5f9c

Browse files
committed
feat: URow, UCol: add flex grow and shrink props
1 parent 7754b5a commit 69c5f9c

File tree

7 files changed

+142
-0
lines changed

7 files changed

+142
-0
lines changed

src/ui.container-col/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export default /*tw*/ {
1212
block: {
1313
true: "w-full",
1414
},
15+
grow: {
16+
true: "flex-grow",
17+
},
18+
shrink: {
19+
true: "flex-shrink",
20+
},
1521
gap: {
1622
none: "gap-0",
1723
"3xs": "gap-0.5",
@@ -61,5 +67,7 @@ export default /*tw*/ {
6167
wrap: false,
6268
reverse: false,
6369
block: false,
70+
grow: false,
71+
shrink: false,
6472
},
6573
};

src/ui.container-col/storybook/stories.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,57 @@ DefaultSlot.args = {
159159
<UButton label="Submit" />
160160
`,
161161
};
162+
163+
export const Grow: StoryFn<UColArgs> = (args: UColArgs) => ({
164+
components: { UCol, UButton },
165+
setup: () => ({ args }),
166+
template: `
167+
<div class="flex flex-col h-[400px] border border-primary border-dashed rounded-medium p-4">
168+
<UCol gap="sm" class="border border-secondary border-dashed rounded-medium p-4">
169+
<UButton label="Col 1" />
170+
<UButton label="No grow" />
171+
</UCol>
172+
<UCol gap="sm" grow class="border border-secondary border-dashed rounded-medium p-4">
173+
<UButton label="Col 2" />
174+
<UButton label="With grow - fills available space" />
175+
</UCol>
176+
<UCol gap="sm" class="border border-secondary border-dashed rounded-medium p-4">
177+
<UButton label="Col 3" />
178+
<UButton label="No grow" />
179+
</UCol>
180+
</div>
181+
`,
182+
});
183+
Grow.parameters = {
184+
docs: {
185+
description: {
186+
story: "Allow flex item to grow to fill available space (flex-grow). The middle column grows to fill the remaining vertical space.",
187+
},
188+
},
189+
};
190+
191+
export const Shrink: StoryFn<UColArgs> = (args: UColArgs) => ({
192+
components: { UCol, UButton },
193+
setup: () => ({ args }),
194+
template: `
195+
<div class="flex flex-col h-[300px] border border-primary border-dashed rounded-medium p-4">
196+
<UCol gap="sm" shrink class="min-h-[200px] border border-secondary border-dashed rounded-medium p-4">
197+
<UButton label="Col 1" />
198+
<UButton label="With shrink - can shrink below min-height" />
199+
<UButton label="Shrinks when needed" />
200+
</UCol>
201+
<UCol gap="sm" class="min-h-[200px] border border-secondary border-dashed rounded-medium p-4">
202+
<UButton label="Col 2" />
203+
<UButton label="No shrink - maintains min-height" />
204+
<UButton label="Won't shrink" />
205+
</UCol>
206+
</div>
207+
`,
208+
});
209+
Shrink.parameters = {
210+
docs: {
211+
description: {
212+
story: "Allow flex item to shrink if necessary (flex-shrink). The first column can shrink below its min-height when space is constrained.",
213+
},
214+
},
215+
};

src/ui.container-col/tests/UCol.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,32 @@ describe("UCol.vue", () => {
140140
expect(component.attributes("class")).toContain(expectedClasses);
141141
});
142142

143+
it("Grow – applies the correct grow class", () => {
144+
const grow = true;
145+
const expectedClasses = "flex-grow";
146+
147+
const component = mount(UCol, {
148+
props: {
149+
grow,
150+
},
151+
});
152+
153+
expect(component.attributes("class")).toContain(expectedClasses);
154+
});
155+
156+
it("Shrink – applies the correct shrink class", () => {
157+
const shrink = true;
158+
const expectedClasses = "flex-shrink";
159+
160+
const component = mount(UCol, {
161+
props: {
162+
shrink,
163+
},
164+
});
165+
166+
expect(component.attributes("class")).toContain(expectedClasses);
167+
});
168+
143169
it("Tag – renders the correct HTML tag", () => {
144170
const tags = ["div", "section", "article", "main", "aside", "nav", "span"];
145171

src/ui.container-col/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ export interface Props {
4949
*/
5050
block?: boolean;
5151

52+
/**
53+
* Allow flex item to grow to fill available space (flex-grow).
54+
*/
55+
grow?: boolean;
56+
57+
/**
58+
* Allow flex item to shrink if necessary (flex-shrink).
59+
*/
60+
shrink?: boolean;
61+
5262
/**
5363
* Allows changing HTML tag.
5464
*/

src/ui.container-row/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export default /*tw*/ {
1212
block: {
1313
true: "w-full",
1414
},
15+
grow: {
16+
true: "flex-grow",
17+
},
18+
shrink: {
19+
true: "flex-shrink",
20+
},
1521
gap: {
1622
none: "gap-0",
1723
"2xs": "gap-1",
@@ -59,5 +65,7 @@ export default /*tw*/ {
5965
wrap: false,
6066
block: false,
6167
reverse: false,
68+
grow: false,
69+
shrink: false,
6270
},
6371
};

src/ui.container-row/tests/URow.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,32 @@ describe("URow.vue", () => {
138138
expect(component.attributes("class")).toContain(expectedClasses);
139139
});
140140

141+
it("Grow – applies the correct grow class", () => {
142+
const grow = true;
143+
const expectedClasses = "flex-grow";
144+
145+
const component = mount(URow, {
146+
props: {
147+
grow,
148+
},
149+
});
150+
151+
expect(component.attributes("class")).toContain(expectedClasses);
152+
});
153+
154+
it("Shrink – applies the correct shrink class", () => {
155+
const shrink = true;
156+
const expectedClasses = "flex-shrink";
157+
158+
const component = mount(URow, {
159+
props: {
160+
shrink,
161+
},
162+
});
163+
164+
expect(component.attributes("class")).toContain(expectedClasses);
165+
});
166+
141167
it("Tag – renders the correct HTML tag", () => {
142168
const tags = ["div", "section", "article", "main", "aside", "nav", "span"];
143169

src/ui.container-row/types.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ export interface Props {
4949
*/
5050
block?: boolean;
5151

52+
/**
53+
* Allow flex item to grow to fill available space (flex-grow).
54+
*/
55+
grow?: boolean;
56+
57+
/**
58+
* Allow flex item to shrink if necessary (flex-shrink).
59+
*/
60+
shrink?: boolean;
61+
5262
/**
5363
* Allows changing HTML tag.
5464
*/

0 commit comments

Comments
 (0)