-
Notifications
You must be signed in to change notification settings - Fork 8
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
Anchored region #530
Merged
Merged
Anchored region #530
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
188f789
first pass
mollykreis 6c20abc
Create anchored-region-matrix.stories.ts
mollykreis b3af70d
Update anchored-region.stories.ts
mollykreis 8edad46
Change files
mollykreis 25c6a15
format
mollykreis 0d5e595
Merge branch 'main' into anchored-region
mollykreis 1226ae0
increase z-index
mollykreis 53853fa
make elements smaller
mollykreis 0c63599
Add docs about updating the anchored region when anchor element changes
mollykreis 7158a82
Merge branch 'main' into anchored-region
mollykreis 6163063
Update packages/nimble-components/src/anchored-region/tests/anchored-β¦
mollykreis 2294cbf
Update packages/nimble-components/src/anchored-region/tests/anchored-β¦
mollykreis 585dab4
Merge branch 'main' into anchored-region
mollykreis e6d5f0f
PR feedback
mollykreis b3d2428
Merge branch 'main' into anchored-region
mollykreis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@ni-nimble-components-a650c15e-7523-460b-8665-4402c06017d5.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "Create nimble-anchored-region", | ||
"packageName": "@ni/nimble-components", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
DesignSystem, | ||
AnchoredRegion as FoundationAnchoredRegion, | ||
anchoredRegionTemplate as template | ||
} from '@microsoft/fast-foundation'; | ||
import { styles } from './styles'; | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
'nimble-anchored-region': AnchoredRegion; | ||
} | ||
} | ||
|
||
/** | ||
* A nimble-styled anchored region control. | ||
*/ | ||
export class AnchoredRegion extends FoundationAnchoredRegion {} | ||
|
||
const nimbleAnchoredRegion = AnchoredRegion.compose({ | ||
baseName: 'anchored-region', | ||
baseClass: FoundationAnchoredRegion, | ||
template, | ||
styles | ||
}); | ||
|
||
DesignSystem.getOrCreate() | ||
.withPrefix('nimble') | ||
.register(nimbleAnchoredRegion()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { css } from '@microsoft/fast-element'; | ||
|
||
export const styles = css` | ||
:host { | ||
contain: layout; | ||
display: block; | ||
z-index: 1; | ||
} | ||
`; |
104 changes: 104 additions & 0 deletions
104
packages/nimble-components/src/anchored-region/tests/anchored-region-matrix.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import type { Meta, Story } from '@storybook/html'; | ||
mollykreis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { html, ViewTemplate } from '@microsoft/fast-element'; | ||
import { | ||
createMatrix, | ||
sharedMatrixParameters | ||
} from '../../utilities/tests/matrix'; | ||
import { createStory } from '../../utilities/tests/storybook'; | ||
import { hiddenWrapper } from '../../utilities/tests/hidden'; | ||
import '../../all-components'; | ||
import { | ||
bodyFont, | ||
bodyFontColor, | ||
borderHoverColor, | ||
applicationBackgroundColor | ||
} from '../../theme-provider/design-tokens'; | ||
|
||
const metadata: Meta = { | ||
title: 'Tests/AnchoredRegion', | ||
mollykreis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
parameters: { | ||
...sharedMatrixParameters() | ||
} | ||
}; | ||
|
||
export default metadata; | ||
|
||
const horizontalPositionStates = [ | ||
['Start', 'start'], | ||
['End', 'end'], | ||
['Left', 'left'], | ||
['Right', 'right'], | ||
['Center', 'center'] | ||
] as const; | ||
type HorizontalPositionState = typeof horizontalPositionStates[number]; | ||
|
||
const verticalPositionStates = [ | ||
['Top', 'top'], | ||
['Bottom', 'bottom'], | ||
['Center', 'center'] | ||
] as const; | ||
type VerticalPositionState = typeof verticalPositionStates[number]; | ||
|
||
const component = ( | ||
[horizontalPositionName, horizontalPosition]: HorizontalPositionState, | ||
[verticalPositionName, verticalPosition]: VerticalPositionState | ||
): ViewTemplate => html`<style> | ||
.container { | ||
display: inline-flex; | ||
margin: 100px; | ||
height: 200px; | ||
width: 200px; | ||
} | ||
|
||
.anchor { | ||
top: 100px; | ||
left: 300px; | ||
width: 150px; | ||
height: 150px; | ||
font: var(${bodyFont.cssCustomProperty}); | ||
color: var(${bodyFontColor.cssCustomProperty}); | ||
border: 2px solid var(${borderHoverColor.cssCustomProperty}); | ||
background: var(${applicationBackgroundColor.cssCustomProperty}); | ||
} | ||
|
||
.anchoredRegion { | ||
width: 75px; | ||
height: 75px; | ||
font: var(${bodyFont.cssCustomProperty}); | ||
color: var(${bodyFontColor.cssCustomProperty}); | ||
border: 2px solid var(${borderHoverColor.cssCustomProperty}); | ||
background: var(${applicationBackgroundColor.cssCustomProperty}); | ||
} | ||
</style> | ||
<div class="container"> | ||
<div | ||
id="${() => `${verticalPosition}_${horizontalPosition}`}" | ||
class="anchor" | ||
> | ||
Anchor element | ||
</div> | ||
<nimble-anchored-region | ||
anchor="${() => `${verticalPosition}_${horizontalPosition}`}" | ||
fixed-placement="true" | ||
auto-update-mode="auto" | ||
vertical-default-position="${() => verticalPosition}" | ||
vertical-positioning-mode="locktodefault" | ||
horizontal-default-position="${() => horizontalPosition}" | ||
horizontal-positioning-mode="locktodefault" | ||
> | ||
<div class="anchoredRegion"> | ||
${horizontalPositionName} ${verticalPositionName} | ||
</div> | ||
</nimble-anchored-region> | ||
<div></div> | ||
</div>`; | ||
|
||
export const anchoredRegionThemeMatrix: Story = createStory( | ||
createMatrix(component, [horizontalPositionStates, verticalPositionStates]) | ||
); | ||
|
||
export const hiddenAnchoredRegion: Story = createStory( | ||
hiddenWrapper( | ||
html`<nimble-anchored-region hidden>Hidden Anchored Region</nimble-anchored-regionx>` | ||
) | ||
); |
19 changes: 19 additions & 0 deletions
19
packages/nimble-components/src/anchored-region/tests/anchored-region.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { | ||
DesignSystem, | ||
AnchoredRegion as FoundationAnchoredRegion | ||
} from '@microsoft/fast-foundation'; | ||
import { AnchoredRegion } from '..'; | ||
|
||
describe('Anchored Region', () => { | ||
it('should have its tag returned by tagFor(FoundationAnchoredRegion)', () => { | ||
expect(DesignSystem.tagFor(FoundationAnchoredRegion)).toBe( | ||
'nimble-anchored-region' | ||
); | ||
}); | ||
|
||
it('can construct an element instance', () => { | ||
expect(document.createElement('nimble-anchored-region')).toBeInstanceOf( | ||
AnchoredRegion | ||
); | ||
}); | ||
}); |
98 changes: 98 additions & 0 deletions
98
packages/nimble-components/src/anchored-region/tests/anchored-region.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import type { Meta, StoryObj } from '@storybook/html'; | ||
import { html } from '@microsoft/fast-element'; | ||
import { createUserSelectedThemeStory } from '../../utilities/tests/storybook'; | ||
import '../../all-components'; | ||
import { | ||
applicationBackgroundColor, | ||
bodyFont, | ||
bodyFontColor, | ||
borderHoverColor | ||
} from '../../theme-provider/design-tokens'; | ||
|
||
interface AnchoredRegionArgs { | ||
horizontalPosition: string; | ||
verticalPosition: string; | ||
} | ||
|
||
const overviewText = `An anchored region is a container component which enables authors to create layouts where the contents of the anchored region can be | ||
mollykreis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
positioned relative to another "anchor" element. Additionally, the anchored region can react to the available space between the anchor and a parent | ||
mollykreis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
["viewport"](https://developer.mozilla.org/en-US/docs/Glossary/viewport) element such that the region is placed on the side of the anchor with the most | ||
available space, or even resize itself based on that space.`; | ||
|
||
const metadata: Meta<AnchoredRegionArgs> = { | ||
title: 'Anchored Region', | ||
mollykreis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
parameters: { | ||
docs: { | ||
description: { | ||
component: overviewText | ||
} | ||
} | ||
}, | ||
// prettier-ignore | ||
render: createUserSelectedThemeStory(html<AnchoredRegionArgs>` | ||
<style> | ||
.container { | ||
height: 300px; | ||
} | ||
|
||
.anchor { | ||
position: absolute; | ||
top: 100px; | ||
left: 300px; | ||
width: 150px; | ||
height: 150px; | ||
font: var(${bodyFont.cssCustomProperty}); | ||
color: var(${bodyFontColor.cssCustomProperty}); | ||
border: 2px solid var(${borderHoverColor.cssCustomProperty}); | ||
background: var(${applicationBackgroundColor.cssCustomProperty}); | ||
} | ||
|
||
.anchoredRegion { | ||
width: 75px; | ||
height: 75px; | ||
font: var(${bodyFont.cssCustomProperty}); | ||
color: var(${bodyFontColor.cssCustomProperty}); | ||
border: 2px solid var(${borderHoverColor.cssCustomProperty}); | ||
background: var(${applicationBackgroundColor.cssCustomProperty}); | ||
} | ||
</style> | ||
<div class="container"> | ||
<div id="${x => `${x.verticalPosition}_${x.horizontalPosition}`}" class="anchor"> | ||
mollykreis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Anchor element | ||
</div> | ||
<nimble-anchored-region | ||
anchor="${x => `${x.verticalPosition}_${x.horizontalPosition}`}" | ||
fixed-placement="true" | ||
auto-update-mode="auto" | ||
vertical-default-position="${x => x.verticalPosition}" | ||
vertical-positioning-mode="${x => (x.verticalPosition === 'unset' ? 'dynamic' : 'locktodefault')}" | ||
horizontal-default-position="${x => x.horizontalPosition}" | ||
horizontal-positioning-mode="${x => (x.horizontalPosition === 'unset' ? 'dynamic' : 'locktodefault')}" | ||
> | ||
<div class="anchoredRegion"> | ||
Anchored region | ||
</div> | ||
</nimble-anchored-region> | ||
</div> | ||
`), | ||
argTypes: { | ||
horizontalPosition: { | ||
options: ['start', 'end', 'left', 'right', 'center', 'unset'], | ||
control: { type: 'select' } | ||
}, | ||
verticalPosition: { | ||
options: ['top', 'bottom', 'center', 'unset'], | ||
control: { type: 'select' } | ||
} | ||
}, | ||
args: {} | ||
}; | ||
|
||
export default metadata; | ||
|
||
export const anchoredRegion: StoryObj<AnchoredRegionArgs> = { | ||
args: { | ||
horizontalPosition: 'start', | ||
mollykreis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
verticalPosition: 'top' | ||
} | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the select and the drawer are also configuring z-index. Do we know how these are impacting eachother? https://cs.github.com/ni/nimble?q=z-index
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I set this to 1 to match the select, and I tested that it worked correctly when put inside of a drawer. However, I just tested the menu button within a grid, and I realized that I need to increase the z-index because the header row in the grid has a z-index of 200.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm changing this to 1000. I tested that the menu button looked correct in SystemLink when it was in a grid's toolbar, in a grid's context menu, in the header, in a drawer, and on a generic page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is 1000 coming from? Is that because it's one more than the drawer? Or it's arbitrarily higher than the 200 z-index in the grid?
Unfortunately FAST doesn't have a system for managing z-index values we can copy.
Could we either in this PR or a follow-on (if a follow-on we should make an issue to track it) make a global enum of the different z-index states we use in our styles (like low, medium, high or something) and can include some docs on how the value is derived (ie we chose 1000 because it's larger than the external grid we have compatibility with)?
Maybe we can eventually have some tokens exported that external consumers can use to align z-indexes with nimble. (or even better longer term we can use the dialog element, etc to do the layering for us without the need for z-index)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I picked something that was arbitrarily higher than the 200 z-index in the grid. We don't need it to be higher than the 999 set on the drawer.
I'll create an issue for making a global enum of z-indexes and address it in separate PR. I'm not sure I see exactly what your vision is, so I'd rather have that discussion on a different PR and not delay this one being merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created issue: #539