Skip to content

Commit 363c966

Browse files
committed
added support for @enableCollapseBelowContentSize argument for Flex::Item
1 parent 61297c3 commit 363c966

File tree

3 files changed

+57
-0
lines changed
  • packages/components/src
  • showcase/app/templates/layouts

3 files changed

+57
-0
lines changed

packages/components/src/components/hds/layout/flex/item.ts

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export interface HdsLayoutFlexItemSignature {
1616
basis?: string | 0;
1717
grow?: boolean | number | string;
1818
shrink?: boolean | number | string;
19+
// TODO final name TBD
20+
enableCollapseBelowContentSize?: boolean;
1921
};
2022
Blocks: {
2123
default: [];
@@ -79,6 +81,11 @@ export default class HdsLayoutFlexItem extends Component<HdsLayoutFlexItemSignat
7981
classes.push('hds-layout-flex-item--shrink-1');
8082
}
8183

84+
// add a class based on the @enableCollapseBelowContentSize argument (applies a `min-width: 0`)
85+
if (this.args.enableCollapseBelowContentSize) {
86+
classes.push('hds-layout-flex-item--enable-collapse-below-content-size');
87+
}
88+
8289
return classes.join(' ');
8390
}
8491
}

packages/components/src/styles/components/layout/flex.scss

+5
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,8 @@
9999
.hds-layout-flex-item--shrink-1 {
100100
flex-shrink: 1;
101101
}
102+
103+
.hds-layout-flex-item--enable-collapse-below-content-size {
104+
// this allows the element to shrink below its content's intrinsic minimum width (eg. used with elliptized text)
105+
min-width: 0;
106+
}

showcase/app/templates/layouts/flex.hbs

+45
Original file line numberDiff line numberDiff line change
@@ -299,4 +299,49 @@
299299
</SG.Item>
300300
</Shw::Grid>
301301

302+
<Shw::Text::H3>enableCollapseBelowContentSize (<code>min-width: 0</code>)</Shw::Text::H3>
303+
304+
<Shw::Grid @columns={{1}} as |SG|>
305+
<SG.Item @label="first flex item has enableCollapseBelowContentSize=true">
306+
<Shw::Outliner {{style max-width="600px"}}>
307+
<Hds::Layout::Flex as |HLF|>
308+
<HLF.Item @enableCollapseBelowContentSize={{true}}>
309+
<Shw::Placeholder @height="40" @background="#e4c5f3">
310+
<pre {{style white-space="nowrap" overflow="hidden" text-overflow="ellipsis"}}>item #1 with a very long text that might cause overflow issues</pre>
311+
</Shw::Placeholder>
312+
</HLF.Item>
313+
<HLF.Item>
314+
<Shw::Placeholder @text="item #2 with width=150px" @width="150px" @height="40" @background="#e5ffd2" />
315+
</HLF.Item>
316+
<HLF.Item>
317+
<Shw::Placeholder @text="item #3 with width=150px" @width="150px" @height="40" @background="#d2f4ff" />
318+
</HLF.Item>
319+
<HLF.Item>
320+
<Shw::Placeholder @text="item #4" @height="40" @background="#fff8d2" />
321+
</HLF.Item>
322+
</Hds::Layout::Flex>
323+
</Shw::Outliner>
324+
</SG.Item>
325+
<SG.Item @label="first flex item has basis=0px">
326+
<Shw::Outliner {{style max-width="600px"}}>
327+
<Hds::Layout::Flex as |HLF|>
328+
<HLF.Item @basis="0px">
329+
<Shw::Placeholder @height="40" @background="#e4c5f3">
330+
<pre {{style white-space="nowrap" overflow="hidden" text-overflow="ellipsis"}}>item #1 with a very long text that might cause overflow issues</pre>
331+
</Shw::Placeholder>
332+
</HLF.Item>
333+
<HLF.Item>
334+
<Shw::Placeholder @text="item #2 with width=150px" @width="150px" @height="40" @background="#e5ffd2" />
335+
</HLF.Item>
336+
<HLF.Item>
337+
<Shw::Placeholder @text="item #3 with width=150px" @width="150px" @height="40" @background="#d2f4ff" />
338+
</HLF.Item>
339+
<HLF.Item>
340+
<Shw::Placeholder @text="item #4" @height="40" @background="#fff8d2" />
341+
</HLF.Item>
342+
</Hds::Layout::Flex>
343+
</Shw::Outliner>
344+
</SG.Item>
345+
</Shw::Grid>
346+
302347
</section>

0 commit comments

Comments
 (0)