style-map.d.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * @license
  3. * Copyright 2018 Google LLC
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. import { AttributePart, noChange } from '../lit-html.js';
  7. import { Directive, DirectiveParameters, PartInfo } from '../directive.js';
  8. /**
  9. * A key-value set of CSS properties and values.
  10. *
  11. * The key should be either a valid CSS property name string, like
  12. * `'background-color'`, or a valid JavaScript camel case property name
  13. * for CSSStyleDeclaration like `backgroundColor`.
  14. */
  15. export interface StyleInfo {
  16. readonly [name: string]: string | undefined | null;
  17. }
  18. declare class StyleMapDirective extends Directive {
  19. _previousStyleProperties?: Set<string>;
  20. constructor(partInfo: PartInfo);
  21. render(styleInfo: StyleInfo): string;
  22. update(part: AttributePart, [styleInfo]: DirectiveParameters<this>): string | typeof noChange;
  23. }
  24. /**
  25. * A directive that applies CSS properties to an element.
  26. *
  27. * `styleMap` can only be used in the `style` attribute and must be the only
  28. * expression in the attribute. It takes the property names in the `styleInfo`
  29. * object and adds the property values as CSS properties. Property names with
  30. * dashes (`-`) are assumed to be valid CSS property names and set on the
  31. * element's style object using `setProperty()`. Names without dashes are
  32. * assumed to be camelCased JavaScript property names and set on the element's
  33. * style object using property assignment, allowing the style object to
  34. * translate JavaScript-style names to CSS property names.
  35. *
  36. * For example `styleMap({backgroundColor: 'red', 'border-top': '5px', '--size':
  37. * '0'})` sets the `background-color`, `border-top` and `--size` properties.
  38. *
  39. * @param styleInfo
  40. */
  41. export declare const styleMap: (styleInfo: StyleInfo) => import("../directive.js").DirectiveResult<typeof StyleMapDirective>;
  42. /**
  43. * The type of the class that powers this directive. Necessary for naming the
  44. * directive's return type.
  45. */
  46. export type { StyleMapDirective };
  47. //# sourceMappingURL=style-map.d.ts.map