-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address brave/brave-browser#5180 Storybook stores several copies of container components. This effort eliminates them in favor of reusing a real-world component. Limitations apply such as lack of dynamic content. State changes are triggered via Storybook Knobs hopefully making easier for non-technical people to understand and hack around Brave features.
- Loading branch information
1 parent
fd203f3
commit 3915d02
Showing
23 changed files
with
191 additions
and
874 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 0 additions & 103 deletions
103
components/brave_new_tab_ui/stories/default/data/background.ts
This file was deleted.
Oops, something went wrong.
Binary file removed
BIN
-28.9 KB
components/brave_new_tab_ui/stories/default/data/siteIcons/appstore.png
Binary file not shown.
Binary file removed
BIN
-3.62 KB
components/brave_new_tab_ui/stories/default/data/siteIcons/facebook.png
Binary file not shown.
Binary file removed
BIN
-6.9 KB
components/brave_new_tab_ui/stories/default/data/siteIcons/playstore.png
Binary file not shown.
Binary file removed
BIN
-2.06 KB
components/brave_new_tab_ui/stories/default/data/siteIcons/twitter.png
Binary file not shown.
Binary file removed
BIN
-1.47 KB
components/brave_new_tab_ui/stories/default/data/siteIcons/youtube.png
Binary file not shown.
64 changes: 64 additions & 0 deletions
64
components/brave_new_tab_ui/stories/default/data/storybookState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { select, boolean, number } from '@storybook/addon-knobs/react' | ||
import { images } from '../../../data/backgrounds' | ||
import { defaultTopSitesData } from '../../../data/defaultTopSites' | ||
import dummyBrandedWallpaper from './brandedWallpaper' | ||
|
||
function generateStaticImages (images: NewTab.Image[]) { | ||
const staticImages = {} | ||
for (const image of images) { | ||
Object.assign(staticImages, { | ||
[image.author]: { | ||
...image, | ||
source: require('../../../../img/newtab/' + image.source) | ||
} | ||
}) | ||
} | ||
return staticImages | ||
} | ||
|
||
function generateTopSites (topSites: typeof defaultTopSitesData) { | ||
const staticTopSites = [] | ||
for (const [index, topSite] of topSites.entries()) { | ||
staticTopSites.push({ | ||
...topSite, | ||
index, | ||
title: topSite.name, | ||
letter: '', | ||
thumb: '', | ||
themeColor: '', | ||
computedThemeColor: '', | ||
pinned: false | ||
}) | ||
} | ||
return staticTopSites | ||
} | ||
|
||
function shouldShowBrandedWallpaperData (shouldShow: boolean) { | ||
if (shouldShow === false) { | ||
return { | ||
BrandedWallpaper: '', | ||
wallpaperImageUrl: '', | ||
logo: { image: '', companyName: '', alt: '', destinationUrl: '' } | ||
} | ||
} | ||
return dummyBrandedWallpaper | ||
} | ||
|
||
export const getNewTabData = (state: NewTab.State) => ({ | ||
...state, | ||
brandedWallpaperData: shouldShowBrandedWallpaperData(boolean('Show branded background image?', true)), | ||
backgroundImage: select('Background image', generateStaticImages(images), generateStaticImages(images)['SpaceX']), | ||
showBackgroundImage: boolean('Show background image?', true), | ||
showStats: boolean('Show stats?', true), | ||
showClock: boolean('Show clock?', true), | ||
showTopSites: boolean('Show top sites?', true), | ||
showRewards: boolean('Show rewards?', true), | ||
textDirection: select('Text direction', { ltr: 'ltr', rtl: 'rtl' } , 'ltr'), | ||
gridSites: generateTopSites(defaultTopSitesData), | ||
stats: { | ||
...state.stats, | ||
adsBlockedStat: number('Number of blocked items', 1337), | ||
httpsUpgradesStat: number('Number of HTTPS upgrades', 1337) | ||
}, | ||
initialDataLoaded: true | ||
}) |
Oops, something went wrong.