ui: css-prop modifier (#12205)

Get the value for a single specific CSS Property from the modified element.
returns can be specified either as a second parameter or an option.
This commit is contained in:
John Cowen 2022-01-27 11:27:38 +00:00 committed by GitHub
parent eac0f5b860
commit de13e207e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,12 @@
import Modifier from 'ember-modifier';
import { inject as service } from '@ember/service';
export default class CSSPropModifier extends Modifier {
@service('-document') doc;
didReceiveArguments() {
const params = this.args.positional;
const options = this.args.named;
const returns = params[1] || options.returns;
returns(this.doc.defaultView.getComputedStyle(this.element).getPropertyValue(params[0]));
}
}

View File

@ -0,0 +1,25 @@
# css-prop
Get the value for a single specific CSS Property from the modified element.
`returns` can be specified either as a second parameter or an option.
```hbs preview-template
<div
{{css-prop '--red-500' returns=(set this 'red')}}
>
<code>--red-500: {{this.red}}</code>
</div>
```
## Positional Arguments
| Argument | Type | Default | Description |
| --- | --- | --- | --- |
| `property` | `string` | | The name of the CSS property to fetch from the element |
| `returns` | `function` | | Usually `set` or `mut` or similar |
## Named Arguments
| Argument | Type | Default | Description |
| --- | --- | --- | --- |
| `returns` | `function` | | See the `returns` positional argument |