@@ -8,83 +8,23 @@ import {
88} from '@angular/core' ;
99
1010import {
11- DaffColorable ,
12- DaffPalette ,
13- DaffPaletteEnum ,
11+ DaffColor ,
12+ DaffColorEnum ,
1413} from './colorable' ;
1514
16- const colorInPalette = ( color : string ) => ( < any > Object ) . values ( DaffPaletteEnum ) . includes ( color ) ;
15+ const isDaffColor = ( color : string ) => ( < any > Object ) . values ( DaffColorEnum ) . includes ( color ) ;
1716
1817const validateColor = ( color : string ) => {
1918 if ( isDevMode ( ) ) {
20- if ( color !== undefined && ! colorInPalette ( color ) ) {
21- console . warn ( color + ' is not a valid color in DaffPalette ' ) ;
19+ if ( color !== undefined && ! isDaffColor ( color ) ) {
20+ console . warn ( color + ' is not a valid color in DaffColor ' ) ;
2221 }
2322 }
2423} ;
2524
2625/**
27- * `DaffColorableDirective` allows a component to conditionally apply color-specific
28- * styles by setting CSS classes based on the specified color. This directive is useful
29- * for applying different color palettes to a component in an Angular application.
30- *
31- * Supported colors: `primary | secondary | tertiary | light | dark | theme | theme-contrast`
32- *
33- * | Color | Class |
34- * | -------- | ----- |
35- * | `primary` | `.daff-primary`|
36- * | `secondary` | `.daff-secondary`|
37- * | `tertiary` | `.daff-tertiary`|
38- * | `light` | `daff-light` |
39- * | `dark` | `daff-dark` |
40- * | `theme` | `daff-theme`|
41- * | `theme-contrast` | `.daff-theme-contrast`|
42- *
43- * `white` and `black` have been deprecated in favor of `light` and `dark`.
44- *
45- * @example Implementing it as an attribute directive
46- *
47- * ```html
48- * <div daffColorable [color]="primary">Colored content</div>
49- * ```
50- *
51- * ```scss
52- * .div {
53- * &.daff-primary {
54- * color: daff-color($primary);
55- * }
56- * }
57- * ```
58- *
59- * In this example, the `daff-primary` class is applied to the `div` element, allowing you to
60- * use the color class to style the `div`.
61- *
62- * @example Implementing it as an Angular host directive
63- *
64- * ```ts
65- * @Component ({
66- * selector: 'custom-component',
67- * template: 'custom-component.html',
68- * hostDirectives: [
69- * {
70- * directive: DaffColorableDirective,
71- * inputs: ['color'],
72- * },
73- * ],
74- * })
75- * export class CustomComponent {
76- * @HostBinding ('class.custom-component') class = true;
77- * }
78- * ```
79- *
80- * ```scss
81- * .custom-component {
82- * &.daff-primary {
83- * background: daff-color($primary, 10);
84- * color: daff-color($primary, 90);
85- * }
86- * }
87- * ```
26+ * Enforces consistent use of {@link DaffColor} on a component by applying
27+ * color-specific CSS classes and validating the color in dev mode.
8828 */
8929@Directive ( {
9030 selector : '[daffColorable]' ,
@@ -100,23 +40,16 @@ const validateColor = (color: string) => {
10040 '[class.daff-white]' : 'color === "white"' ,
10141 } ,
10242} )
103- export class DaffColorableDirective implements DaffColorable , OnChanges , OnInit {
43+ export class DaffColorableDirective implements OnChanges , OnInit {
10444 /**
105- * Sets the color on a component.
45+ * The color of the component.
10646 */
107- @Input ( ) color : DaffPalette ;
47+ @Input ( ) color : DaffColor ;
10848
10949 /**
110- * Sets a default color.
111- *
112- * @example
113- * ```ts
114- * constructor(private colorableDirective: DaffColorableDirective) {
115- * this.colorableDirective.defaultColor = 'theme';
116- * }
117- * ```
50+ * The default color used when no color is set.
11851 */
119- defaultColor : DaffPalette ;
52+ defaultColor : DaffColor ;
12053
12154 /**
12255 * @docs -private
0 commit comments