Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OSCI] Adding props for shrink and basis for OuiFlexItem #1126

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d7426fe
adding shrink and basis props for OuiFlexItem
BigSamu Oct 27, 2023
0cf7375
adding tests for shrink and basis props added in OuiFlexItem
BigSamu Oct 27, 2023
fe28556
changing API for values accepted for basis prop and updating snapshoo…
BigSamu Oct 28, 2023
d5dd922
updating CHANGELOG.md and testing snapshoots
BigSamu Oct 30, 2023
a4362a8
Merge branch 'main' into feat/props-ouiFlexItem
BigSamu Nov 1, 2023
3eb7413
changing location of chanelog description for this issue into correct…
BigSamu Nov 1, 2023
428ef63
fixing typo lines 122 and 123 flexItem.tsx
BigSamu Nov 1, 2023
eb68e2c
fixing typo line 55 file _flex_item.scss
BigSamu Nov 1, 2023
9665bba
updating jest unit-testing snapshoots
BigSamu Nov 1, 2023
b8ec51e
changing default values for shrink and basis props
BigSamu Nov 1, 2023
8abdb38
removing class .ouiFlexItem--flexShrinkZero from _flex_item.scss and …
BigSamu Nov 1, 2023
34fad9a
updating documentation for shrink and basis props in OuiFlexItem
BigSamu Nov 1, 2023
4674627
updating jest unit-testing snapshoots
BigSamu Nov 1, 2023
29aff44
removing extra line CHANELOG.md
BigSamu Nov 4, 2023
74354d0
Merge branch 'main' into feat/props-ouiFlexItem
BigSamu Nov 8, 2023
6914c7d
refactoring code adding after suggestions from code review in last PR
BigSamu Nov 9, 2023
345fd2d
adding snapshoots for unit-testing
BigSamu Nov 9, 2023
e74f52e
Merge branch 'main' into feat/props-ouiFlexItem
BigSamu Nov 17, 2023
8d6e8fa
Adding tests for combinatios of grow, shrink and basis values and res…
BigSamu Nov 17, 2023
c58f11a
removing property flex-basis:auto from CSS class ouiFlexItem--flexShr…
BigSamu Nov 17, 2023
66c8e9e
modifiying logic for prop 'basis' according what was requested by mai…
BigSamu Nov 21, 2023
a539b13
Merge branch 'main' into feat/props-ouiFlexItem
BigSamu Jan 1, 2024
fb97c87
Merge branch 'main' into feat/props-ouiFlexItem
BigSamu Jan 11, 2024
e4e0aff
Update src-docs/src/views/flex/flex_basis_string.tsx
BigSamu Jan 12, 2024
2341eab
Update src-docs/src/views/flex/flex_shrink_numeric.tsx
BigSamu Jan 12, 2024
ceed1ce
updating text for examples of Basis in flex items
BigSamu Jan 12, 2024
01e94ea
adding 0 item for GROW_SIZES and SHRINK_SIZES arrays and FlexItemGrow…
BigSamu Jan 12, 2024
03ce677
make 'true' and 'false' options for types FlexItemGrowSize and FlexIt…
BigSamu Jan 12, 2024
9fd51c9
updating snapshoots
BigSamu Jan 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- Update ouiTextSubduedColor in `next` dark theme ([#973](https://github.com/opensearch-project/oui/pull/973))
- Add `crossInCircleEmpty` and `power` icons ([#1044](https://github.com/opensearch-project/oui/pull/1044))
- Add `Figma` icon and link to OUI Figma resources ([#1064](https://github.com/opensearch-project/oui/pull/1064))
- Add `shrink` and `basis` props to OuiFlexItem ([#1126](https://github.com/opensearch-project/oui/pull/1126))

### 🐛 Bug Fixes

Expand Down
43 changes: 43 additions & 0 deletions src-docs/src/views/flex/flex_basis_string.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
BigSamu marked this conversation as resolved.
Show resolved Hide resolved

import React from 'react';

import { OuiFlexGroup, OuiFlexItem } from '../../../../src/components/flex';

export default () => (
<div>
<OuiFlexGroup>
<OuiFlexItem basis={'auto'}>
Auto
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the actual value of the prop we want users to use is auto, we should use auto here and not Auto. Also, we should perhaps wrap it in OuiCode?

The same goes for all of the other values too.

@kgcreative

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AMoo-Miki,

Updated text in examples for Basis in Flex Item for all basis properties (e.g.Auto to auto). Just one question what is this suggestion of wrapping with OuiCode?

<br />
Varies based on content size or width/height property
</OuiFlexItem>
<OuiFlexItem basis={'fit-content'}>
Fit-content
<br />
Sizes the item based on the content&apos;s width but within the
container.
</OuiFlexItem>
<OuiFlexItem basis={'max-content'}>
Max-content
<br />
Sizes the item to be as large as the content&apos;s maximum width.
</OuiFlexItem>
<OuiFlexItem basis={'min-content'}>
Min-content
<br />
Sizes the item to be as small as the content&apos;s minimum width
without breaking.
</OuiFlexItem>
</OuiFlexGroup>
</div>
);
82 changes: 79 additions & 3 deletions src-docs/src/views/flex/flex_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ const flexGrowZeroSource = require('!!raw-loader!./flex_grow_zero');
import FlexGrowNumeric from './flex_grow_numeric';
const flexGrowNumericSource = require('!!raw-loader!./flex_grow_numeric');

import FlexShrinkNumeric from './flex_shrink_numeric';
const flexShrinkNumericSource = require('!!raw-loader!./flex_shrink_numeric');

import FlexBasisString from './flex_basis_string';
const FlexBasisStringSource = require('!!raw-loader!./flex_basis_string');

import FlexJustify from './flex_justify';
const flexJustifySource = require('!!raw-loader!./flex_justify');
import FlexJustifyBetween from './flex_justify_between';
Expand Down Expand Up @@ -105,10 +111,31 @@ const flexGrowZeroSnippet = `<OuiFlexGroup>
</OuiFlexGroup>`;

const flexGrowNumericSnippet = `<OuiFlexGroup>
<OuiFlexItem grow={1}><!-- FlexItem with flew-grow 1 --></OuiFlexItem>
<OuiFlexItem grow={2}><!-- FlexItem with flew-grow 2 --></OuiFlexItem>
<OuiFlexItem grow={1}><!-- FlexItem with flex-grow 1 --></OuiFlexItem>
<OuiFlexItem grow={2}><!-- FlexItem with flex-grow 2 --></OuiFlexItem>
...
<OuiFlexItem grow={10}><!-- FlexItem with flex-grow 10 --></OuiFlexItem>
</OuiFlexGroup>`;

const flexShrinkNumericSnippet = `<OuiFlexGroup>
<OuiFlexItem grow={false} shrink={1}><!-- FlexItem with flex-shrink 1 --></OuiFlexItem>
<OuiFlexItem grow={false} shrink={2}><!-- FlexItem with flex-shrink 2 --></OuiFlexItem>
...
<OuiFlexItem grow={10}><!-- FlexItem with flew-grow 10 --></OuiFlexItem>
<OuiFlexItem grow={false} shrink={10}><!-- FlexItem with flex-shrink 10 --></OuiFlexItem>
</OuiFlexGroup>

<OuiFlexGroup>
<OuiFlexItem shrink={1} basis={'auto'}><!-- FlexItem with flex-shrink 1 --></OuiFlexItem>
<OuiFlexItem shrink={2} basis={'auto'}><!-- FlexItem with flex-shrink 2 --></OuiFlexItem>
...
<OuiFlexItem shrink={10} basis={'auto'}><!-- FlexItem with flex-shrink 10 --></OuiFlexItem>
</OuiFlexGroup>`;

const flexBasisStringSnippet = `<OuiFlexGroup>
<OuiFlexItem basis={'auto'}><!-- FlexItem with flex-basis 'auto' --></OuiFlexItem>
<OuiFlexItem basis={'fit-content'}><!-- FlexItem with flex-basis 'fit-content' --></OuiFlexItem>
<OuiFlexItem basis={'max-content'}><!-- FlexItem with flex-basis 'max-content' --></OuiFlexItem>
<OuiFlexItem basis={'min-content'}><!-- FlexItem with flex-basis 'min-content' --></OuiFlexItem>
</OuiFlexGroup>`;

const directionSnippet = `<OuiFlexGroup direction="column">
Expand Down Expand Up @@ -328,6 +355,55 @@ export const FlexExample = {
</div>
),
},
{
title: 'Proportional shrinking of items',
source: [
{
type: GuideSectionTypes.JS,
code: flexShrinkNumericSource,
},
],
text: (
<p>
You can specify a number between 1 and 10 for each{' '}
<strong>OuiFlexItem</strong> to take up a proportional shrinking of
the <strong>OuiFlexGroup</strong> it is in. For this to apply: (1) the
BigSamu marked this conversation as resolved.
Show resolved Hide resolved
prop <strong>grow</strong> should set into <strong>false</strong> or
change the <strong>basis</strong> prop to <strong>auto</strong> and
(2) the content in the all flex item should be sufficient enough to
reach the width of the flex parent.
</p>
),
snippet: flexShrinkNumericSnippet,
demo: (
<div className="guideDemo__highlightGrid">
<FlexShrinkNumeric />
</div>
),
},
{
title: 'Basis of flex items',
source: [
{
type: GuideSectionTypes.JS,
code: FlexBasisStringSource,
},
],
text: (
<p>
You can also specify the <strong>flex-basis</strong> CSS property of a
flex item using the <strong>basis</strong> prop with one of the
following options: <strong>auto</strong>, <strong>content-fit</strong>
, <strong>content-max</strong>, <strong>content-min</strong>
</p>
),
snippet: flexBasisStringSnippet,
demo: (
<div className="guideDemo__highlightGrid">
<FlexBasisString />
</div>
),
},
{
title: 'Justify and align',
source: [
Expand Down
51 changes: 51 additions & 0 deletions src-docs/src/views/flex/flex_shrink_numeric.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
BigSamu marked this conversation as resolved.
Show resolved Hide resolved

import React from 'react';

import { OuiFlexGroup, OuiFlexItem } from '../../../../src/components/flex';
import { OuiSpacer } from '../../../../src/components/spacer';

export default () => (
<div>
<OuiFlexGroup>
<OuiFlexItem grow={false} shrink={1}>
Extensive Text Extensive Text Extensive Text
BigSamu marked this conversation as resolved.
Show resolved Hide resolved
</OuiFlexItem>
<OuiFlexItem grow={false} shrink={2}>
Extensive Text Extensive Text Extensive Text
</OuiFlexItem>
<OuiFlexItem grow={false} shrink={4}>
Extensive Text Extensive Text Extensive Text
</OuiFlexItem>
<OuiFlexItem grow={false} shrink={8}>
Extensive Text Extensive Text Extensive Text
</OuiFlexItem>
</OuiFlexGroup>

<OuiSpacer />

<OuiFlexGroup>
<OuiFlexItem shrink={1} basis={'auto'}>
Extensive Text Extensive Text Extensive Text
</OuiFlexItem>
<OuiFlexItem shrink={2} basis={'auto'}>
Extensive Text Extensive Text Extensive Text
</OuiFlexItem>
<OuiFlexItem shrink={4} basis={'auto'}>
Extensive Text Extensive Text Extensive Text
</OuiFlexItem>
<OuiFlexItem shrink={8} basis={'auto'}>
Extensive Text Extensive Text Extensive Text
</OuiFlexItem>
</OuiFlexGroup>
</div>
);
84 changes: 84 additions & 0 deletions src/components/flex/__snapshots__/flex_item.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`OuiFlexItem basis auto is rendered 1`] = `
<div
class="ouiFlexItem ouiFlexItem--flexBasis-auto"
/>
`;

exports[`OuiFlexItem basis fit-content is rendered 1`] = `
<div
class="ouiFlexItem ouiFlexItem--flexBasis-fit-content"
/>
`;

exports[`OuiFlexItem basis max-content is rendered 1`] = `
<div
class="ouiFlexItem ouiFlexItem--flexBasis-max-content"
/>
`;

exports[`OuiFlexItem basis min-content is rendered 1`] = `
<div
class="ouiFlexItem ouiFlexItem--flexBasis-min-content"
/>
`;

exports[`OuiFlexItem grow 1 is rendered 1`] = `
<div
class="ouiFlexItem ouiFlexItem--flexGrow1"
Expand Down Expand Up @@ -79,3 +103,63 @@ exports[`OuiFlexItem is rendered 1`] = `
data-test-subj="test subject string"
/>
`;

exports[`OuiFlexItem shrink 1 is rendered 1`] = `
<div
class="ouiFlexItem ouiFlexItem--flexShrink1"
/>
`;

exports[`OuiFlexItem shrink 2 is rendered 1`] = `
<div
class="ouiFlexItem ouiFlexItem--flexShrink2"
/>
`;

exports[`OuiFlexItem shrink 3 is rendered 1`] = `
<div
class="ouiFlexItem ouiFlexItem--flexShrink3"
/>
`;

exports[`OuiFlexItem shrink 4 is rendered 1`] = `
<div
class="ouiFlexItem ouiFlexItem--flexShrink4"
/>
`;

exports[`OuiFlexItem shrink 5 is rendered 1`] = `
<div
class="ouiFlexItem ouiFlexItem--flexShrink5"
/>
`;

exports[`OuiFlexItem shrink 6 is rendered 1`] = `
<div
class="ouiFlexItem ouiFlexItem--flexShrink6"
/>
`;

exports[`OuiFlexItem shrink 7 is rendered 1`] = `
<div
class="ouiFlexItem ouiFlexItem--flexShrink7"
/>
`;

exports[`OuiFlexItem shrink 8 is rendered 1`] = `
<div
class="ouiFlexItem ouiFlexItem--flexShrink8"
/>
`;

exports[`OuiFlexItem shrink 9 is rendered 1`] = `
<div
class="ouiFlexItem ouiFlexItem--flexShrink9"
/>
`;

exports[`OuiFlexItem shrink 10 is rendered 1`] = `
<div
class="ouiFlexItem ouiFlexItem--flexShrink10"
/>
`;
1 change: 1 addition & 0 deletions src/components/flex/_flex_group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
}

flex-grow: 1;
flex-shrink: 1;
flex-basis: 0%; /* 2 */
}
}
Expand Down
38 changes: 34 additions & 4 deletions src/components/flex/_flex_item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,48 @@

/*
* 1. We need the extra specificity here to override the FlexGroup > FlexItem styles.
* 2. FlexItem can be manually set to not grow if needed.
* 2. FlexItem can be manually set to not grow or shrink if needed (default allows grow and shrink).
* 3. FlexItem basis can be set to 'auto' (defaul use flex-basis: 0%)
* 4. FlexItem also can be given values for grow, shrink and basis:
* - grow: 1..10
* - shrink: 1..10
* - basis: auto, max-content, min-content, fit-content
*/

&.ouiFlexItem--flexGrowZero { /* 1 */
flex-grow: 0; /* 2 */
flex-basis: auto; /* 2 */
}

@for $i from 1 through 10 {
&.ouiFlexItem--flexGrow#{$i} {
flex-grow: $i;
&.ouiFlexItem--flexShrinkZero { /* 1 */
BigSamu marked this conversation as resolved.
Show resolved Hide resolved
flex-shrink: 0; /* 2 */
flex-basis: auto; /* 2 */
BSFishy marked this conversation as resolved.
Show resolved Hide resolved
}

&.ouiFlexItem--flexBasisAuto { /* 1 */
flex-basis: auto; /* 3 */
}

@for $i from 1 through 10 { /* 4 */
&.ouiFlexItem--flexGrow#{$i} { /* 4 */
flex-grow: $i; /* 4 */
}
}

@for $i from 1 through 10 { /* 4 */
&.ouiFlexItem--flexShrink#{$i} { /* 4 */
flex-shrink: $i; /* 4 */
}
}

$flexBasisOptions: auto, max-content, min-content, fit-content; /* 4 */

@each $basis in $flexBasisOptions { /* 4 */
&.ouiFlexItem--flexBasis-#{$basis} { /* 4 */
flex-basis: $basis; /* 3 */
}
}

}

// On mobile we force them to stack and act the same.
Expand Down
Loading