|
| 1 | +import React, { FC } from 'react'; |
| 2 | + |
| 3 | +import ELEMENTS from '@public-ui/components/custom-elements.json'; |
| 4 | + |
| 5 | +const BLACKLIST = [ |
| 6 | + 'kol-button-group', |
| 7 | + 'kol-color', |
| 8 | + 'kol-counter', |
| 9 | + 'kol-heading-wc', |
| 10 | + 'kol-icon-font-awesome', |
| 11 | + 'kol-icon-icofont', |
| 12 | + 'kol-input-adapter-leanup', |
| 13 | + 'kol-input-radio-group', |
| 14 | + 'kol-kolibri', |
| 15 | + 'kol-logo', |
| 16 | + 'kol-link-group', |
| 17 | + 'kol-span', |
| 18 | + 'kol-span-wc', |
| 19 | + 'kol-version', |
| 20 | +]; |
| 21 | +type Property = 'components' | 'descriptions' | 'types'; |
| 22 | +const COMPONENTS = new Map(); |
| 23 | +const PROPS = new Map<string, Map<Property, Set<string>>>(); |
| 24 | +ELEMENTS.tags.forEach((tag) => { |
| 25 | + if (BLACKLIST.indexOf(tag.name) === -1) { |
| 26 | + const componentName = tag.name.replace('kol-', ''); |
| 27 | + if (COMPONENTS.has(componentName) === false) { |
| 28 | + COMPONENTS.set(componentName, { |
| 29 | + desc: tag.description, |
| 30 | + props: new Set(), |
| 31 | + }); |
| 32 | + } |
| 33 | + tag.attributes.forEach((attribute) => { |
| 34 | + if (PROPS.has(attribute.name) === false) { |
| 35 | + const MAP = new Map<Property, Set<string>>(); |
| 36 | + MAP.set('components', new Set()); |
| 37 | + MAP.set('descriptions', new Set()); |
| 38 | + MAP.set('types', new Set()); |
| 39 | + PROPS.set(attribute.name, MAP); |
| 40 | + } |
| 41 | + const prop = PROPS.get(attribute.name); |
| 42 | + if (prop) { |
| 43 | + prop.get('components').add(componentName); |
| 44 | + prop.get('descriptions').add(attribute.description); |
| 45 | + prop.get('types').add(attribute.type.replace(/ \| undefined/g, '')); |
| 46 | + } |
| 47 | + }); |
| 48 | + } |
| 49 | +}); |
| 50 | + |
| 51 | +const hideButton = new Map<Property, Set<string>>(); |
| 52 | +hideButton.set('components', new Set(['kol-pagination'])); |
| 53 | +hideButton.set('descriptions', new Set(['Versteckt entweder den Zurück- oder Weiter-Schalter, oder beide Schalter.'])); |
| 54 | +hideButton.set('types', new Set(['"previous" | "next" | "both"'])); |
| 55 | +PROPS.set('_hide-button', hideButton); |
| 56 | + |
| 57 | +const DEPRECATED = new Map<string, Set<string>>(); |
| 58 | +DEPRECATED.set('_align', new Set(['_alignment'])); |
| 59 | +DEPRECATED.set('_hide-button', new Set(['_has-buttons'])); |
| 60 | +DEPRECATED.set('_hide-label', new Set(['_icon-only'])); |
| 61 | +DEPRECATED.set('_label', new Set(['_aria-label', '_caption', '_heading', '_headline', '_quote', '_summary', '_symbol', '_title'])); |
| 62 | +// DEPRECATED.set('_list', new Set(['_links'])); |
| 63 | +DEPRECATED.set('_variant', new Set(['_type<sup>*</sup>'])); |
| 64 | +DEPRECATED.set('', new Set(['_has-buttons', '_has-footer', '_height', '_icon-align', '_part', '_show-dropdown'])); |
| 65 | + |
| 66 | +export const Properties: FC = () => { |
| 67 | + return ( |
| 68 | + <div> |
| 69 | + <p> |
| 70 | + Ziel ist, möglichst über alle Komponenten einheitliche Eigenschaften (Properties) zu verwenden, um die Erlernbarkeit zu erleichtern. Folgende |
| 71 | + Anforderungen sind dafür definiert: |
| 72 | + </p> |
| 73 | + <ul> |
| 74 | + <li>Nur ein Property-Name für gleichartige Eigenschaften</li> |
| 75 | + <li>Wenn möglich, einheitliche Beschreibungen bei gleichen Propterty-Namen</li> |
| 76 | + <li>Wenn möglich, einheitliche Typen bei gleichen Propterty-Namen</li> |
| 77 | + <li>Anzahl an unterschiedlichen Properties, Beschreibungen und Typen minimieren</li> |
| 78 | + </ul> |
| 79 | + <h2>Aktueller Stand</h2> |
| 80 | + <table> |
| 81 | + <thead> |
| 82 | + <tr> |
| 83 | + <th>#</th> |
| 84 | + <th>Property</th> |
| 85 | + <th>Components</th> |
| 86 | + <th>Descriptions</th> |
| 87 | + <th>Types</th> |
| 88 | + </tr> |
| 89 | + </thead> |
| 90 | + <tbody> |
| 91 | + {Array.from(PROPS.keys()).map((prop, index) => { |
| 92 | + const components = Array.from(PROPS.get(prop)?.get('components') || []); |
| 93 | + const descriptions = Array.from(PROPS.get(prop)?.get('descriptions') || []); |
| 94 | + const types = Array.from(PROPS.get(prop)?.get('types') || []); |
| 95 | + return ( |
| 96 | + <tr key={prop}> |
| 97 | + <td>{index}</td> |
| 98 | + <td>{prop}</td> |
| 99 | + <td>{components.join(', ')}</td> |
| 100 | + <td |
| 101 | + style={{ backgroundColor: descriptions.length > 1 && '#fbc' }} |
| 102 | + dangerouslySetInnerHTML={{ |
| 103 | + __html: descriptions.join('<hr/>'), |
| 104 | + }} |
| 105 | + /> |
| 106 | + <td |
| 107 | + style={{ backgroundColor: types.length > 1 && '#fbc' }} |
| 108 | + dangerouslySetInnerHTML={{ |
| 109 | + __html: types.join('"<hr/>"'), |
| 110 | + }} |
| 111 | + /> |
| 112 | + </tr> |
| 113 | + ); |
| 114 | + })} |
| 115 | + </tbody> |
| 116 | + </table> |
| 117 | + <h2>Deprecated</h2> |
| 118 | + <p>Die in der folgenden Tabelle aufgelisteten Eigenschaften lösen zahlreiche veraltete Eigenschaften (-{Math.round((16 / PROPS.size) * 100)}%) ab.</p> |
| 119 | + <table> |
| 120 | + <thead> |
| 121 | + <tr> |
| 122 | + <th>New Property</th> |
| 123 | + <th>Deprecates Properties</th> |
| 124 | + </tr> |
| 125 | + </thead> |
| 126 | + <tbody> |
| 127 | + {Array.from(DEPRECATED.keys()).map((prop) => { |
| 128 | + const deprecated = Array.from(DEPRECATED.get(prop) || []); |
| 129 | + return ( |
| 130 | + <tr key={prop}> |
| 131 | + <td>{prop}</td> |
| 132 | + <td |
| 133 | + dangerouslySetInnerHTML={{ |
| 134 | + __html: deprecated.join(', '), |
| 135 | + }} |
| 136 | + ></td> |
| 137 | + </tr> |
| 138 | + ); |
| 139 | + })} |
| 140 | + </tbody> |
| 141 | + </table> |
| 142 | + <p> |
| 143 | + <small> |
| 144 | + <sup>*</sup> Betrifft nur Typen, die eigentlich Varianten meinen. |
| 145 | + </small> |
| 146 | + </p> |
| 147 | + </div> |
| 148 | + ); |
| 149 | +}; |
0 commit comments