style-map.d.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. [name: string]: string | number | undefined | null;
  17. }
  18. declare class StyleMapDirective extends Directive {
  19. private _previousStyleProperties?;
  20. constructor(partInfo: PartInfo);
  21. render(styleInfo: Readonly<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
  29. * {@link StyleInfo styleInfo} object and adds the properties to the inline
  30. * style of the element.
  31. *
  32. * Property names with dashes (`-`) are assumed to be valid CSS
  33. * property names and set on the element's style object using `setProperty()`.
  34. * Names without dashes are assumed to be camelCased JavaScript property names
  35. * and set on the element's style object using property assignment, allowing the
  36. * style object to translate JavaScript-style names to CSS property names.
  37. *
  38. * For example `styleMap({backgroundColor: 'red', 'border-top': '5px', '--size':
  39. * '0'})` sets the `background-color`, `border-top` and `--size` properties.
  40. *
  41. * @param styleInfo
  42. * @see {@link https://lit.dev/docs/templates/directives/#stylemap styleMap code samples on Lit.dev}
  43. */
  44. export declare const styleMap: (styleInfo: Readonly<StyleInfo>) => import("../directive.js").DirectiveResult<typeof StyleMapDirective>;
  45. /**
  46. * The type of the class that powers this directive. Necessary for naming the
  47. * directive's return type.
  48. */
  49. export type { StyleMapDirective };
  50. //# sourceMappingURL=style-map.d.ts.map