|
| 1 | +import {ButtonProps} from '../schema/validators/common'; |
| 2 | +import {ImageProps, urlPattern} from '../components/Image/schema'; |
| 3 | +import {omit} from 'lodash'; |
| 4 | +import {filteredArray} from '../schema/validators/utils'; |
| 5 | + |
| 6 | +const NavigationItemType = { |
| 7 | + type: 'string', |
| 8 | + enum: ['link', 'button', 'dropdown'], |
| 9 | +}; |
| 10 | + |
| 11 | +export const LogoProps = { |
| 12 | + type: 'object', |
| 13 | + additionalProperties: false, |
| 14 | + required: ['icon'], |
| 15 | + properties: { |
| 16 | + icon: ImageProps, |
| 17 | + text: { |
| 18 | + type: 'string', |
| 19 | + contentType: 'text', |
| 20 | + }, |
| 21 | + url: { |
| 22 | + type: 'string', |
| 23 | + }, |
| 24 | + }, |
| 25 | +}; |
| 26 | + |
| 27 | +const NavigationItemBaseProps = { |
| 28 | + text: { |
| 29 | + type: 'string', |
| 30 | + contentType: 'text', |
| 31 | + }, |
| 32 | + url: { |
| 33 | + type: 'string', |
| 34 | + }, |
| 35 | + icon: { |
| 36 | + type: 'string', |
| 37 | + pattern: urlPattern, |
| 38 | + }, |
| 39 | +}; |
| 40 | + |
| 41 | +const NavigationItemBaseLinkProps = omit(NavigationItemBaseProps, ['url']); |
| 42 | + |
| 43 | +const NavigationLinkItemProps = { |
| 44 | + type: 'object', |
| 45 | + additionalProperties: false, |
| 46 | + required: ['type', 'text'], |
| 47 | + properties: { |
| 48 | + ...NavigationItemBaseLinkProps, |
| 49 | + type: {...NavigationItemType}, |
| 50 | + url: { |
| 51 | + type: 'string', |
| 52 | + }, |
| 53 | + target: { |
| 54 | + type: 'string', |
| 55 | + }, |
| 56 | + arrow: { |
| 57 | + type: 'boolean', |
| 58 | + }, |
| 59 | + }, |
| 60 | +}; |
| 61 | + |
| 62 | +const NavigationButtonItemProps = { |
| 63 | + type: 'object', |
| 64 | + additionalProperties: false, |
| 65 | + required: ['type', 'text', 'url'], |
| 66 | + properties: { |
| 67 | + ...ButtonProps, |
| 68 | + type: {...NavigationItemType}, |
| 69 | + }, |
| 70 | +}; |
| 71 | + |
| 72 | +const NavigationDropdownItemProps = { |
| 73 | + type: 'object', |
| 74 | + additionalProperties: false, |
| 75 | + required: ['type', 'items'], |
| 76 | + properties: { |
| 77 | + ...NavigationItemBaseProps, |
| 78 | + type: {...NavigationItemType}, |
| 79 | + items: filteredArray(NavigationLinkItemProps), |
| 80 | + }, |
| 81 | +}; |
| 82 | + |
| 83 | +const NavigationItemProps = { |
| 84 | + oneOf: [ |
| 85 | + filteredArray(NavigationLinkItemProps), |
| 86 | + filteredArray(NavigationButtonItemProps), |
| 87 | + filteredArray(NavigationDropdownItemProps), |
| 88 | + ], |
| 89 | +}; |
| 90 | + |
| 91 | +export const NavigationHeaderProps = { |
| 92 | + type: 'object', |
| 93 | + additionalProperties: false, |
| 94 | + required: ['leftItems'], |
| 95 | + properties: { |
| 96 | + leftItems: NavigationItemProps, |
| 97 | + rightItems: NavigationItemProps, |
| 98 | + }, |
| 99 | +}; |
0 commit comments