-
Notifications
You must be signed in to change notification settings - Fork 159
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
feat(link-list): aem improvements to end-of-section type #4972
Changes from 1 commit
4a3260c
3883bf2
b58e29c
8209b58
2d4af96
2074679
f3b0b32
5289281
00ffc5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
/** | ||
* @license | ||
* | ||
* Copyright IBM Corp. 2020 | ||
* Copyright IBM Corp. 2020, 2021 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { css, customElement } from 'lit-element'; | ||
import { css, customElement, property } from 'lit-element'; | ||
import ddsSettings from '@carbon/ibmdotcom-utilities/es/utilities/settings/settings.js'; | ||
import DDSLinkWithIcon from '../link-with-icon/link-with-icon'; | ||
import styles from './link-list.scss'; | ||
|
||
import { LINK_LIST_ITEM_TYPE } from './defs'; | ||
|
||
export { LINK_LIST_ITEM_TYPE }; | ||
|
||
const { stablePrefix: ddsPrefix } = ddsSettings; | ||
|
||
/** | ||
|
@@ -21,6 +25,9 @@ const { stablePrefix: ddsPrefix } = ddsSettings; | |
*/ | ||
@customElement(`${ddsPrefix}-link-list-item`) | ||
class DDSLinkListItem extends DDSLinkWithIcon { | ||
@property({ reflect: true }) | ||
type = LINK_LIST_ITEM_TYPE.DEFAULT; | ||
Comment on lines
+31
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a JSDoc comment that describes what this property is for? That will be reflected to docs page in Storybook. |
||
|
||
connectedCallback() { | ||
if (!this.hasAttribute('role')) { | ||
this.setAttribute('role', 'listitem'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,16 @@ | |
} | ||
} | ||
|
||
:host(#{$dds-prefix}-link-list-item) { | ||
:host(#{$dds-prefix}-link-list-item)[type='end'] { | ||
outline: none; | ||
|
||
&:hover { | ||
.#{$prefix}--link { | ||
text-decoration: none; | ||
background: $ui-03; | ||
} | ||
} | ||
|
||
.#{$prefix}--link { | ||
> span { | ||
flex: 1; | ||
|
@@ -95,4 +102,24 @@ | |
} | ||
} | ||
} | ||
|
||
.#{$dds-prefix}-ce--link-list__list--three-columns { | ||
@include carbon--breakpoint('sm') { | ||
::slotted(#{$dds-prefix}-link-list-item) { | ||
margin-right: -$carbon--layout-01; | ||
} | ||
} | ||
|
||
@include carbon--breakpoint('md') { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr 1fr; | ||
grid-column-gap: 2rem; | ||
|
||
::slotted(#{$dds-prefix}-link-list-item) { | ||
display: block; | ||
margin-left: -$carbon--layout-01; | ||
margin-right: 0; | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There seem many duplicate CSS rules with two columns mode. One way to solve it is: .#{$dds-prefix}-ce--link-list__list--split {
/* The common rules */
}
.#{$dds-prefix}-ce--link-list__list--two-columns {
/* 2-column mode-specific rules */
}
.#{$dds-prefix}-ce--link-list__list--three-columns {
/* 3-column mode-specific rules */
} .#{$dds-prefix}-ce--link-list__list--split,
.#{$dds-prefix}-ce--link-list__list--three-columns {
/* The common rules */
} |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import ddsSettings from '@carbon/ibmdotcom-utilities/es/utilities/settings/setti | |
import StableSelectorMixin from '../../globals/mixins/stable-selector'; | ||
import { LINK_LIST_TYPE } from './defs'; | ||
import styles from './link-list.scss'; | ||
import DDSLinkListItem, { LINK_LIST_ITEM_TYPE } from './link-list-item'; | ||
|
||
export { LINK_LIST_TYPE }; | ||
|
||
|
@@ -35,6 +36,13 @@ class DDSLinkList extends StableSelectorMixin(LitElement) { | |
@internalProperty() | ||
private _useSplitLayoutForEndType = false; | ||
|
||
/** | ||
* `true` to use three column layout for `type="end"` | ||
* Should happen if there are more than 6 child items slotted in. | ||
*/ | ||
@internalProperty() | ||
private _useThreeColumnLayoutForEndType = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you rename |
||
|
||
/** | ||
* Handler for @slotChange, toggles the split layout class and set the children link-list-item to the same height | ||
* | ||
|
@@ -45,7 +53,13 @@ class DDSLinkList extends StableSelectorMixin(LitElement) { | |
const childItems = (event.target as HTMLSlotElement) | ||
.assignedNodes({ flatten: true }) | ||
.filter(node => node.nodeType === Node.ELEMENT_NODE && (node as Element)?.matches(selectorItem)) as Element[]; | ||
this._useSplitLayoutForEndType = childItems.length > 3; | ||
this._useSplitLayoutForEndType = childItems.length > 3 && childItems.length < 7; | ||
this._useThreeColumnLayoutForEndType = childItems.length >= 7; | ||
if (this.type === LINK_LIST_TYPE.END) { | ||
childItems.forEach(elem => { | ||
(elem as DDSLinkListItem).type = LINK_LIST_ITEM_TYPE.END; | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make sure updating |
||
} | ||
|
||
/** | ||
|
@@ -55,7 +69,11 @@ class DDSLinkList extends StableSelectorMixin(LitElement) { | |
type = LINK_LIST_TYPE.DEFAULT; | ||
|
||
render() { | ||
const { type, _useSplitLayoutForEndType: useSplitLayoutForEndType } = this; | ||
const { | ||
type, | ||
_useSplitLayoutForEndType: useSplitLayoutForEndType, | ||
_useThreeColumnLayoutForEndType: useThreeColumnLayoutForEndType, | ||
} = this; | ||
const headingClasses = classMap({ | ||
[`${ddsPrefix}-ce--link-list__heading__wrapper`]: true, | ||
[`${ddsPrefix}-ce--link-list__heading--split`]: type === LINK_LIST_TYPE.END && useSplitLayoutForEndType, | ||
|
@@ -70,6 +88,7 @@ class DDSLinkList extends StableSelectorMixin(LitElement) { | |
[`${prefix}--link-list__list`]: true, | ||
[listTypeClasses]: true, | ||
[`${ddsPrefix}-ce--link-list__list--split`]: type === LINK_LIST_TYPE.END && useSplitLayoutForEndType, | ||
[`${ddsPrefix}-ce--link-list__list--three-columns`]: type === LINK_LIST_TYPE.END && useThreeColumnLayoutForEndType, | ||
}); | ||
return html` | ||
<div class="${headingClasses}"><slot name="heading"></slot></div> | ||
|
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.