-
Notifications
You must be signed in to change notification settings - Fork 33
Use overflowEllipsisDeclarations when lines=1 #7293
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -2,15 +2,14 @@ import '../colors/colors.js'; | |
| import '../icons/icon.js'; | ||
| import '../tooltip/tooltip.js'; | ||
| import { css, html, LitElement, nothing } from 'lit'; | ||
| import { getOverflowDeclarations, overflowEllipsisDeclarations } from '../../helpers/overflow.js'; | ||
| import { _generateLinkStyles } from './link-styles.js'; | ||
| import { classMap } from 'lit/directives/class-map.js'; | ||
| import { FocusMixin } from '../../mixins/focus/focus-mixin.js'; | ||
| import { getOverflowDeclarations } from '../../helpers/overflow.js'; | ||
| import { getUniqueId } from '../../helpers/uniqueId.js'; | ||
| import { ifDefined } from 'lit/directives/if-defined.js'; | ||
| import { LocalizeCoreElement } from '../../helpers/localize-core-element.js'; | ||
| import { offscreenStyles } from '../offscreen/offscreen.js'; | ||
| import { styleMap } from 'lit/directives/style-map.js'; | ||
|
|
||
| export const linkStyles = _generateLinkStyles('.d2l-link', true); | ||
|
|
||
|
|
@@ -90,12 +89,6 @@ class Link extends LocalizeCoreElement(FocusMixin(LitElement)) { | |
| align-items: baseline; | ||
| display: flex; | ||
| } | ||
| a span.truncate { | ||
| ${getOverflowDeclarations({ lines: 1 })} | ||
| } | ||
| a span.truncate-one { | ||
| ${overflowEllipsisDeclarations} | ||
| } | ||
| #new-window { | ||
| line-height: 0; | ||
| white-space: nowrap; | ||
|
|
@@ -157,12 +150,7 @@ class Link extends LocalizeCoreElement(FocusMixin(LitElement)) { | |
| 'd2l-link-main': this.main, | ||
| 'd2l-link-small': this.small | ||
| }; | ||
| const spanClasses = { | ||
| 'd2l-link-content': true, | ||
| 'truncate': this.lines > 1, | ||
| 'truncate-one': this.lines === 1 | ||
| }; | ||
| const styles = { webkitLineClamp: this.lines || null }; | ||
| const styles = this.lines ? getOverflowDeclarations({ lines: this.lines }) : null; | ||
| const newWindowElements = (this.target === '_blank') | ||
| ? html`<span id="new-window"><span style="font-size: 0;"> </span><d2l-icon icon="tier1:new-window"></d2l-icon></span><span class="d2l-offscreen">${this.localize('components.link.open-in-new-window')}</span>` | ||
| : nothing; | ||
|
|
@@ -186,17 +174,14 @@ class Link extends LocalizeCoreElement(FocusMixin(LitElement)) { | |
| tabindex="${ifDefined(this.disabled && this.disabledTooltip ? 0 : undefined)}" | ||
| target="${ifDefined(this.target)}" | ||
| ><span | ||
| class="${classMap(spanClasses)}" | ||
| style="${styleMap(styles)}"><slot></slot></span>${newWindowElements}</a>${disabledTooltip}`; | ||
| class="d2l-link-content" | ||
| style="${styles ?? nothing}"><slot></slot></span>${newWindowElements}</a>${disabledTooltip}`; | ||
| } | ||
|
|
||
| #linkId = getUniqueId(); | ||
|
|
||
| #handleClick(e) { | ||
| if (this.disabled) { | ||
| e.stopPropagation(); | ||
| e.preventDefault(); | ||
| } | ||
|
Contributor
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. Missing
Contributor
Author
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. That suggestion was impossible to get to render correctly and it still broke anyway after 3 tries |
||
| #handleClick() { | ||
| if (this.disabled) return false; | ||
|
bearfriend marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,22 @@ | ||
| import { set } from './template-tags.js'; | ||
| import { unsafeCSS } from 'lit'; | ||
|
|
||
| export const overflowHiddenDeclarations = getOverflowDeclarations({}); | ||
| export const overflowEllipsisDeclarations = getOverflowDeclarations({ textOverflow: 'ellipsis' }); | ||
| export const overflowHiddenDeclarations = getOverflowDeclarations({ lines: 0 }); | ||
| export const overflowEllipsisDeclarations = getOverflowDeclarations({ textOverflow: 'ellipsis', lines: 0 }); | ||
|
|
||
| export function getOverflowDeclarations({ textOverflow = '', lines = 0, lit = true } = {}) { | ||
| export function getOverflowDeclarations({ textOverflow = '', lines = 1, lit = true } = {}) { | ||
| if (!arguments.length) return overflowHiddenDeclarations; | ||
| if (arguments[0].lines === 1) return overflowEllipsisDeclarations; | ||
|
Contributor
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 this not ignore the
Contributor
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. Also does just
Contributor
Author
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.
|
||
|
|
||
| const declarations = set` | ||
| min-width: 0; /* clamps width of flex items */ | ||
| overflow-x: clip; | ||
| ${lines | ||
| ${lines > 1 || lines.constructor === String | ||
| ? set` | ||
| display: -webkit-box; | ||
| overflow-clip-margin: 0.2em; | ||
| overflow-wrap: anywhere; | ||
| overflow-y: clip; | ||
| text-overflow: ${textOverflow || 'ellipsis'}; | ||
| -webkit-box-orient: vertical; | ||
| -webkit-line-clamp: ${lines};` | ||
| : set` | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this 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.
Instead of handling 1 and >1 lines cases with separate classes, we can use the same it seemed simpler to just apply the styles inline. Even though the same call gets us the correct style now, the stylesheet doesn't update with property changes so it needs to either happen on render, or go back to separate classes