|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * |
| 4 | + * Copyright IBM Corp. 2021 |
| 5 | + * |
| 6 | + * This source code is licensed under the Apache-2.0 license found in the |
| 7 | + * LICENSE file in the root directory of this source tree. |
| 8 | + */ |
| 9 | + |
| 10 | +import { html } from 'lit-element'; |
| 11 | +import { select } from '@storybook/addon-knobs'; |
| 12 | +import on from 'carbon-components/es/globals/js/misc/on'; |
| 13 | +import ifNonNull from 'carbon-web-components/es/globals/directives/if-non-null.js'; |
| 14 | +import inPercy from '@percy-io/in-percy'; |
| 15 | +import DDSLeftNav from '../left-nav'; |
| 16 | +import '../masthead-container'; |
| 17 | +import '../cloud/cloud-masthead-container'; |
| 18 | +import styles from './masthead.stories.scss'; |
| 19 | +import { mastheadLinks as links } from './links'; |
| 20 | +import { authenticatedProfileItems, unauthenticatedProfileItems } from './profile-items'; |
| 21 | +import readme from './README.stories.mdx'; |
| 22 | +import { DDS_CLOUD_MASTHEAD } from '../../../globals/internal/feature-flags'; |
| 23 | + |
| 24 | +/** |
| 25 | + * platform knob data |
| 26 | + */ |
| 27 | +const platformData = { |
| 28 | + name: 'IBM Cloud', |
| 29 | + url: 'https://www.ibm.com/cloud', |
| 30 | +}; |
| 31 | + |
| 32 | +export const Default = !DDS_CLOUD_MASTHEAD |
| 33 | + ? undefined |
| 34 | + : ({ parameters }) => { |
| 35 | + const { hasProfile, hasSearch, selectedMenuItem, searchPlaceholder, userStatus, navLinks } = |
| 36 | + parameters?.props?.CloudMastheadComposite ?? {}; |
| 37 | + const { useMock } = parameters?.props?.Other ?? {}; |
| 38 | + return html` |
| 39 | + <style> |
| 40 | + ${styles} |
| 41 | + </style> |
| 42 | + ${useMock |
| 43 | + ? html` |
| 44 | + <dds-cloud-masthead-composite |
| 45 | + platform="Cloud" |
| 46 | + platform-url="${ifNonNull(platformData.url)}" |
| 47 | + selected-menu-item="${ifNonNull(selectedMenuItem)}" |
| 48 | + user-status="${ifNonNull(userStatus)}" |
| 49 | + searchPlaceholder="${ifNonNull(searchPlaceholder)}" |
| 50 | + .authenticatedProfileItems="${ifNonNull(authenticatedProfileItems)}" |
| 51 | + ?has-profile="${hasProfile}" |
| 52 | + ?has-search="${hasSearch}" |
| 53 | + .navLinks="${navLinks}" |
| 54 | + .unauthenticatedProfileItems="${ifNonNull(unauthenticatedProfileItems)}" |
| 55 | + ></dds-cloud-masthead-composite> |
| 56 | + ` |
| 57 | + : html` |
| 58 | + <dds-cloud-masthead-container |
| 59 | + platform="Cloud" |
| 60 | + platform-url="${ifNonNull(platformData.url)}" |
| 61 | + selected-menu-item="${ifNonNull(selectedMenuItem)}" |
| 62 | + user-status="${ifNonNull(userStatus)}" |
| 63 | + searchPlaceholder="${ifNonNull(searchPlaceholder)}" |
| 64 | + .navLinks="${navLinks}" |
| 65 | + ?has-profile="${hasProfile}" |
| 66 | + ?has-search="${hasSearch}" |
| 67 | + data-endpoint="/common/carbon-for-ibm-dotcom/translations/cloud-masthead/jsononly" |
| 68 | + ></dds-cloud-masthead-container> |
| 69 | + `} |
| 70 | + `; |
| 71 | + }; |
| 72 | + |
| 73 | +export default !DDS_CLOUD_MASTHEAD |
| 74 | + ? undefined |
| 75 | + : { |
| 76 | + title: 'Components/Cloud Masthead', |
| 77 | + decorators: [ |
| 78 | + story => { |
| 79 | + if (!(window as any)._hPageShow) { |
| 80 | + (window as any)._hPageShow = on(window, 'pageshow', () => { |
| 81 | + const leftNav = document.querySelector('dds-left-nav'); |
| 82 | + if (leftNav) { |
| 83 | + (leftNav as DDSLeftNav).expanded = false; |
| 84 | + } |
| 85 | + }); |
| 86 | + } |
| 87 | + return story(); |
| 88 | + }, |
| 89 | + ], |
| 90 | + parameters: { |
| 91 | + ...readme.parameters, |
| 92 | + 'carbon-theme': { disabled: true }, |
| 93 | + knobs: { |
| 94 | + escapeHTML: false, |
| 95 | + CloudMastheadComposite: ({ groupId }) => ({ |
| 96 | + userStatus: select( |
| 97 | + 'The user authenticated status (user-status)', |
| 98 | + ['authenticated', 'anonymous'], |
| 99 | + 'anonymous', |
| 100 | + groupId |
| 101 | + ), |
| 102 | + }), |
| 103 | + }, |
| 104 | + props: (() => { |
| 105 | + // Lets `<dds-cloud-masthead-container>` load the nav links |
| 106 | + const useMock = inPercy() || new URLSearchParams(window.location.search).has('mock'); |
| 107 | + return { |
| 108 | + MastheadComposite: { |
| 109 | + navLinks: !useMock ? undefined : links, |
| 110 | + }, |
| 111 | + Other: { |
| 112 | + useMock, |
| 113 | + }, |
| 114 | + }; |
| 115 | + })(), |
| 116 | + }, |
| 117 | + }; |
0 commit comments