-
Notifications
You must be signed in to change notification settings - Fork 105
chore: use UI5 Web Component extension for ObjectPageAnchorTabs #1814
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
Merged
MarcusNotheis
merged 5 commits into
refactor/object-page
from
chore/object-page-anchor-custom-webcomponent
Jul 13, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6abba92
chore: use custom web component for object page anchor bar
MarcusNotheis ee27725
refactor
MarcusNotheis d8dbaaf
Update ObjectPage.test.tsx.snap
MarcusNotheis 45f9769
define icon dependency via static get dependencies
MarcusNotheis c4ec018
update imports
MarcusNotheis 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
This file contains hidden or 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
141 changes: 141 additions & 0 deletions
141
packages/main/src/components/ObjectPage/ObjectPageAnchorTab.ts
This file contains hidden or 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,141 @@ | ||
| /* eslint-disable no-underscore-dangle */ | ||
| import ifDefined from '@ui5/webcomponents-base/dist/renderer/ifDefined.js'; | ||
| import { html, setSuffix, setTags } from '@ui5/webcomponents-base/dist/renderer/LitRenderer.js'; | ||
| import { ThemingParameters } from '@ui5/webcomponents-react-base/dist/ThemingParameters'; | ||
| import Icon from '@ui5/webcomponents/dist/Icon.js'; | ||
| import Tab from '@ui5/webcomponents/dist/Tab.js'; | ||
| import TabContainer from '@ui5/webcomponents/dist/TabContainer.js'; | ||
| import { DetailedHTMLProps, HTMLAttributes, MouseEventHandler } from 'react'; | ||
|
|
||
| interface ObjectPageAnchorTabPropTypes extends HTMLAttributes<HTMLElement> { | ||
| text: string; | ||
| 'with-sub-sections'?: boolean; | ||
| selected?: boolean; | ||
| } | ||
|
|
||
| declare global { | ||
| // eslint-disable-next-line @typescript-eslint/no-namespace | ||
| namespace JSX { | ||
| interface IntrinsicElements { | ||
| 'ui5-object-page-anchor-tab': DetailedHTMLProps<ObjectPageAnchorTabPropTypes, HTMLElement>; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const metadata = { | ||
| tag: 'ui5-object-page-anchor-tab', | ||
| properties: { | ||
| withSubSections: { | ||
| type: Boolean | ||
| } | ||
| }, | ||
| events: { | ||
| 'show-sub-sections': {} | ||
| } | ||
| }; | ||
|
|
||
| class ObjectPageAnchorTab extends Tab { | ||
| static get metadata() { | ||
| return metadata; | ||
| } | ||
|
|
||
| static get dependencies() { | ||
| return [Icon]; | ||
| } | ||
|
|
||
| static get stripTemplate() { | ||
| return (context, tags, suffix) => { | ||
| setTags(tags); | ||
| setSuffix(suffix); | ||
| return html` <li | ||
| id="${ifDefined(context._id)}" | ||
| class="${ifDefined(context.headerClasses)}" | ||
| tabindex="${ifDefined(context._tabIndex)}" | ||
| role="tab" | ||
| aria-posinset="${ifDefined(context._posinset)}" | ||
| aria-setsize="${ifDefined(context._setsize)}" | ||
| aria-controls="ui5-tc-contentItem-${ifDefined(context._posinset)}" | ||
| aria-selected="${ifDefined(context.effectiveSelected)}" | ||
| aria-disabled="${ifDefined(context.effectiveDisabled)}" | ||
| ?disabled="${context.effectiveDisabled}" | ||
| aria-labelledby="${ifDefined(context.ariaLabelledBy)}" | ||
| data-ui5-stable="${ifDefined(context.stableDomRef)}" | ||
| style="list-style-type: none;" | ||
| > | ||
| <div class="ui5-tab-strip-itemContent"> | ||
| ${context.text | ||
| ? html`<span | ||
| class="ui5-tab-strip-itemText" | ||
| id="${ifDefined(context._id)}-text" | ||
| ?data-active="${ifDefined(context.withSubSections)}" | ||
| > | ||
| ${ifDefined(context.text)} | ||
| </span>` | ||
| : undefined} | ||
| ${context.withSubSections | ||
| ? html`<ui5-icon | ||
| name="slim-arrow-down" | ||
| class="objectPageSubSectionsIcon" | ||
| interactive | ||
| @click="${context._handleOnSubSectionsClick}" | ||
| />` | ||
| : undefined} | ||
| </div> | ||
| </li>`; | ||
| }; | ||
| } | ||
|
|
||
| _handleOnSubSectionsClick: MouseEventHandler<HTMLElement> = (e) => { | ||
| e.stopPropagation(); | ||
| e.preventDefault(); | ||
| // eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
| // @ts-ignore | ||
| this.fireEvent('show-sub-sections', { | ||
| targetRef: (e.target as any).parentElement.parentElement | ||
| }); | ||
| }; | ||
|
|
||
| // maybe we can look into a custom overflow template as well | ||
| // static get overflowTemplate() { | ||
| // return (context, tags, suffix) => { | ||
| // setTags(tags); | ||
| // setSuffix(suffix); | ||
| // return html`<ui5-li-custom | ||
| // id="${ifDefined(context._id)}" | ||
| // class="${ifDefined(context.overflowClasses)}" | ||
| // type="${ifDefined(context.overflowState)}" | ||
| // ?selected="${context.effectiveSelected}" | ||
| // ?disabled="${context.effectiveDisabled}" | ||
| // aria-disabled="${ifDefined(context.effectiveDisabled)}" | ||
| // aria-selected="${ifDefined(context.effectiveSelected)}" | ||
| // aria-labelledby="${ifDefined(context.ariaLabelledBy)}" | ||
| // > | ||
| // <div class="ui5-tab-overflow-itemContent">${ifDefined(context.text)}</div> | ||
| // </ui5-li-custom>`; | ||
| // }; | ||
| // } | ||
| } | ||
|
|
||
| TabContainer.registerTabStyles(` | ||
|
|
||
| .ui5-tab-strip-itemContent { | ||
| display: flex; | ||
| align-items: center; | ||
| pointer-events: all; | ||
| } | ||
|
|
||
| .objectPageSubSectionsIcon { | ||
| padding-left: 0.625rem; | ||
| } | ||
|
|
||
| .objectPageSubSectionsIcon[interactive]:hover { | ||
| color: ${ThemingParameters.sapContent_IconColor}; | ||
| } | ||
|
|
||
| .ui5-tab-strip-itemText[data-active]:hover { | ||
| color: ${ThemingParameters.sapButton_Lite_Hover_TextColor}; | ||
| } | ||
| `); | ||
| // TabContainer.registerStaticAreaTabStyles(overflowCss); | ||
|
|
||
| export { ObjectPageAnchorTab }; | ||
Oops, something went wrong.
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.
Probably not a concern right now, but this code will not be affected by suffixing since internally used components (
ui5-icon) are hard-coded.The litHTML unsafe static function must be used to wrap all calls to
ui5-tags in the template.