-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: color-coded tags and page types
- Loading branch information
1 parent
95303f8
commit 67a8047
Showing
12 changed files
with
134 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* eslint-disable react/display-name */ | ||
import React from 'react'; | ||
import { DocumentItem } from '.'; | ||
import { BlockContext } from '../context'; | ||
import { MockContext } from '../test/MockContext'; | ||
|
||
export default { | ||
title: 'Blocks/DocumentItem', | ||
component: DocumentItem, | ||
}; | ||
|
||
export const overview = () => ( | ||
<MockContext storyId="id-of-story"> | ||
<BlockContext.Consumer> | ||
{({ storeProvider, docId }) => { | ||
const page = storeProvider.getStoryDoc(docId || 'id-of-story'); | ||
console.log(page, docId, storeProvider); | ||
return page ? ( | ||
<DocumentItem | ||
config={storeProvider.config} | ||
link={storeProvider.getPagePath(page.type, page.title)} | ||
page={page} | ||
/> | ||
) : null; | ||
}} | ||
</BlockContext.Consumer> | ||
</MockContext> | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* eslint-disable react/display-name */ | ||
import React from 'react'; | ||
import { PageTypeTag } from '.'; | ||
import { MockContext } from '../test/MockContext'; | ||
|
||
export default { | ||
title: 'Blocks/PageTypeTag', | ||
component: PageTypeTag, | ||
}; | ||
|
||
export const overview = () => ( | ||
<MockContext storyId="id-of-story"> | ||
<PageTypeTag type="story" /> | ||
</MockContext> | ||
); |
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,34 @@ | ||
import React, { FC, useState, useEffect, useContext } from 'react'; | ||
import { PageType } from '@component-controls/core'; | ||
import { | ||
Tag, | ||
Link, | ||
getAccentPaletteColor, | ||
} from '@component-controls/components'; | ||
import { BlockContext } from '../context'; | ||
|
||
export interface PageTypeTagProps { | ||
type: PageType; | ||
} | ||
export const PageTypeTag: FC<PageTypeTagProps> = ({ type }) => { | ||
const { storeProvider } = useContext(BlockContext); | ||
const { config } = storeProvider; | ||
const [colors, setColors] = useState<{ [key: string]: string }>({}); | ||
useEffect(() => { | ||
const uniqueTypes = storeProvider.getUniquesByCategory('type'); | ||
setColors( | ||
Object.keys(uniqueTypes).reduce( | ||
(acc, key, index) => ({ | ||
...acc, | ||
[key]: getAccentPaletteColor(index), | ||
}), | ||
{}, | ||
), | ||
); | ||
}, [storeProvider]); | ||
return ( | ||
<Link href={`/${config?.pages?.[type].basePath}`}> | ||
<Tag color={colors[type] || '#f49342'}>{type}</Tag> | ||
</Link> | ||
); | ||
}; |
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 @@ | ||
export * from './PageTypeTag'; |
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
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