-
Notifications
You must be signed in to change notification settings - Fork 33
GAUD-8866 remove button scss from bsi #7254
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 all commits
2a23449
6f95cd5
65c7403
d4e7589
bdaa91a
1b940c7
d8cc5ac
b8e0b55
db3b0ac
01efe0b
35c239f
aaece08
c0e9ad4
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,33 +1,145 @@ | ||
| import '../colors/colors.js'; | ||
| import { css } from 'lit'; | ||
| import { css, unsafeCSS } from 'lit'; | ||
| import { _isValidCssSelector } from '../../helpers/internal/css.js'; | ||
| import { getFocusRingStyles } from '../../helpers/focus.js'; | ||
|
|
||
| export const buttonStyles = css` | ||
| button { | ||
| border-end-end-radius: var(--d2l-button-end-end-radius, 0.3rem); | ||
| border-end-start-radius: var(--d2l-button-end-start-radius, 0.3rem); | ||
| border-start-end-radius: var(--d2l-button-start-end-radius, 0.3rem); | ||
| border-start-start-radius: var(--d2l-button-start-start-radius, 0.3rem); | ||
| border-style: none; | ||
| box-sizing: border-box; | ||
| cursor: pointer; | ||
| display: inline-block; | ||
| margin: 0; | ||
| min-height: calc(2rem + 2px); | ||
| outline: none; | ||
| text-align: center; | ||
| -webkit-user-select: none; | ||
| -moz-user-select: none; | ||
| -ms-user-select: none; | ||
| user-select: none; | ||
| vertical-align: middle; | ||
| white-space: nowrap; | ||
| width: auto; | ||
| } | ||
| ${getFocusRingStyles('button')} | ||
| @media (prefers-contrast: more) { | ||
| button { | ||
| border: 2px solid transparent; | ||
| function _generateButtonBaseStyles(selector) { | ||
| if (!_isValidCssSelector(selector)) return unsafeCSS(''); | ||
| selector = unsafeCSS(selector.trim()); | ||
|
|
||
| return css` | ||
| ${selector} { | ||
| border-end-end-radius: var(--d2l-button-end-end-radius, 0.3rem); | ||
| border-end-start-radius: var(--d2l-button-end-start-radius, 0.3rem); | ||
| border-start-end-radius: var(--d2l-button-start-end-radius, 0.3rem); | ||
| border-start-start-radius: var(--d2l-button-start-start-radius, 0.3rem); | ||
| border-style: none; | ||
| box-sizing: border-box; | ||
| cursor: pointer; | ||
| display: inline-block; | ||
| margin: 0; | ||
| min-height: calc(2rem + 2px); | ||
| outline: none; | ||
| text-align: center; | ||
| -webkit-user-select: none; | ||
| -moz-user-select: none; | ||
| -ms-user-select: none; | ||
| user-select: none; | ||
| vertical-align: middle; | ||
| white-space: nowrap; | ||
| width: auto; | ||
| } | ||
| `; | ||
| } | ||
|
|
||
| function _generateMozillaButtonBorderStyles(selector) { | ||
| return css` | ||
| /* Firefox includes a hidden border which messes up button dimensions */ | ||
|
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. Lots of generator methods. Was hoping core would just have two - one for the base styles (defined in the mixin), and another for the d2l-button styles. Can this be combined with the template immediately above?
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. So I have done the following:
|
||
| ${selector}::-moz-focus-inner { | ||
| border: 0; | ||
| } | ||
| `; | ||
| } | ||
|
|
||
| function _generateButtonDisabledStyles(selector, isForBsi = false) { | ||
| const activeDisabledSelector = isForBsi ? unsafeCSS(`${selector}[active][disabled]`) : unsafeCSS(`:host([active]) ${selector}[disabled]`); | ||
|
|
||
| return css` | ||
| ${selector}, | ||
| ${selector}[disabled]:hover, | ||
| ${selector}[disabled]:focus, | ||
| ${activeDisabledSelector} { | ||
| background-color: var(--d2l-theme-background-color-interactive-secondary-default); | ||
| color: var(--d2l-theme-text-color-static-standard); | ||
| } | ||
| `; | ||
| } | ||
|
|
||
| function _generateButtonEnabledStyles(selector, isForBsi = false) { | ||
| const activeSelector = isForBsi ? unsafeCSS(`${selector}[active]`) : unsafeCSS(`:host([active]) ${selector}`); | ||
| const additionalBSISelector = isForBsi ? unsafeCSS(`${selector}.d2l-button-hover, ${selector}.d2l-button-focus,`) : unsafeCSS(''); | ||
|
|
||
| return css` | ||
| ${additionalBSISelector} | ||
| ${selector}:hover, | ||
| ${selector}:focus, | ||
| ${activeSelector} { | ||
| background-color: var(--d2l-theme-background-color-interactive-secondary-hover); | ||
| } | ||
| `; | ||
| } | ||
|
|
||
| function _generatePrimaryButtonDisabledStyles(selector, isForBsi = false) { | ||
| const finalSelector = isForBsi ? `${selector}[primary], | ||
| ${selector}[primary][disabled]:hover, | ||
| ${selector}[primary][disabled]:focus, | ||
| ${selector}[primary][active][disabled]` : `:host([primary]) ${selector}, | ||
| :host([primary]) ${selector}[disabled]:hover, | ||
| :host([primary]) ${selector}[disabled]:focus, | ||
| :host([primary][active]) ${selector}[disabled]`; | ||
|
|
||
| return css` | ||
| ${unsafeCSS(finalSelector)} { | ||
| background-color: var(--d2l-theme-background-color-interactive-primary-default); | ||
| color: var(--d2l-theme-text-color-static-inverted); | ||
| } | ||
| `; | ||
| } | ||
|
|
||
| function _generatePrimaryButtonEnabledStyles(selector, isForBsi = false) { | ||
| const finalSelector = isForBsi ? `${selector}[primary]:hover, | ||
| ${selector}[primary].d2l-button-hover, | ||
| ${selector}[primary]:focus, | ||
| ${selector}[primary].d2l-button-focus, | ||
| ${selector}[primary][active]` : `:host([primary]) ${selector}:hover, | ||
| :host([primary]) ${selector}:focus, | ||
| :host([primary][active]) ${selector}`; | ||
|
|
||
| return css` | ||
| ${unsafeCSS(finalSelector)} { | ||
| background-color: var(--d2l-theme-background-color-interactive-primary-hover); | ||
| } | ||
| `; | ||
| } | ||
|
|
||
| /** | ||
| * A private helper method that should not be used by general consumers | ||
| */ | ||
| export function _generateBSIButtonFocusStyles(selector) { | ||
| const getSelector = (focusPseudoClass) => ` | ||
| ${selector}:${focusPseudoClass}, | ||
| ${selector}.d2l-button-focus, | ||
| ${selector}[primary]:${focusPseudoClass}, | ||
| ${selector}[primary].d2l-button-focus`; | ||
|
|
||
| return getFocusRingStyles(getSelector); | ||
| } | ||
|
|
||
| /** | ||
| * A private helper method that should not be used by general consumers | ||
| */ | ||
| export function _generateButtonStyles(selector) { | ||
| if (!_isValidCssSelector(selector)) return unsafeCSS(''); | ||
| const safeSelector = unsafeCSS(selector.trim()); | ||
|
|
||
| return css` | ||
| ${safeSelector} { | ||
| font-family: inherit; | ||
| padding-block-end: 0; | ||
| padding-block-start: 0; | ||
| padding-inline-end: var(--d2l-button-padding-inline-end, 1.5rem); | ||
| padding-inline-start: var(--d2l-button-padding-inline-start, 1.5rem); | ||
| } | ||
| } | ||
|
|
||
| ${_generateMozillaButtonBorderStyles(safeSelector)} | ||
| ${_generateButtonDisabledStyles(safeSelector)} | ||
| ${_generateButtonEnabledStyles(safeSelector)} | ||
| ${_generatePrimaryButtonDisabledStyles(safeSelector)} | ||
| ${_generatePrimaryButtonEnabledStyles(safeSelector)} | ||
| `; | ||
| } | ||
|
|
||
| export const buttonStyles = css` | ||
| ${_generateButtonBaseStyles('button')} | ||
| ${getFocusRingStyles('button', { preferContrastMediaQueryExtraStyles: css`border: 2px solid transparent;` })} | ||
| `; | ||
|
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. The deletes styles from this component are now being generated using the |
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 think would be better if you use the split view so you can see what was replaced by what