-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plasma-new-hope): Add
ViewContainer
and examples
- Loading branch information
1 parent
5135dc1
commit 42b7e1c
Showing
16 changed files
with
378 additions
and
12 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
packages/plasma-new-hope/.storybook/decoratorViewContainer.tsx
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,33 @@ | ||
import React from 'react'; | ||
|
||
import { ViewContainer } from '../src/examples/plasma_b2c/components/ViewContainer/ViewContainer'; | ||
|
||
import { ThemeType, themes } from '../src/examples/themes'; | ||
|
||
export const withViewContainer = (Story, context) => { | ||
const themeType = context.globals.theme as keyof ThemeType; | ||
const themeName = context.title.split('/')[0]; | ||
|
||
return ( | ||
<div id="theme-root" className={themes?.[themeName]?.[themeType]}> | ||
<div id="theme-root-popup-1" style={{ border: '1px solid coral' }}> | ||
<h3>Default view</h3> | ||
<ViewContainer> | ||
<Story {...context} /> | ||
</ViewContainer> | ||
</div> | ||
<div id="theme-root-popup-2" style={{ border: '1px solid coral', background: 'black', color: 'white' }}> | ||
<h3>OnDark view</h3> | ||
<ViewContainer view="onDark"> | ||
<Story {...context} /> | ||
</ViewContainer> | ||
</div> | ||
<div id="theme-root-popup-3" style={{ border: '1px solid coral', background: 'white', color: 'black' }}> | ||
<h3>OnLight view</h3> | ||
<ViewContainer view="onLight"> | ||
<Story {...context} /> | ||
</ViewContainer> | ||
</div> | ||
</div> | ||
); | ||
}; |
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
42 changes: 42 additions & 0 deletions
42
packages/plasma-new-hope/src/components/ViewContainer/ViewContainer.tsx
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,42 @@ | ||
import React, { forwardRef } from 'react'; | ||
import { css } from '@linaria/core'; | ||
|
||
import type { RootProps } from '../../engines/types'; | ||
|
||
import { base as viewCSS } from './_view/base'; | ||
|
||
const base = css` | ||
position: relative; | ||
`; | ||
|
||
export type ViewContainerCustomProps = { | ||
/** | ||
* Вид компонента. | ||
*/ | ||
view?: string; | ||
}; | ||
|
||
type ViewContainerProps = React.HTMLAttributes<HTMLDivElement> & ViewContainerCustomProps; | ||
|
||
export const viewContainerRoot = (Root: RootProps<HTMLAnchorElement, ViewContainerProps>) => | ||
forwardRef<HTMLAnchorElement, ViewContainerProps>((props, ref) => { | ||
const { children, ...rest } = props; | ||
|
||
return ( | ||
<Root ref={ref} {...rest}> | ||
{children} | ||
</Root> | ||
); | ||
}); | ||
|
||
export const viewContainerConfig = { | ||
name: 'ViewContainer', | ||
tag: 'div', | ||
layout: viewContainerRoot, | ||
base, | ||
variations: { | ||
view: { | ||
css: viewCSS, | ||
}, | ||
}, | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/plasma-new-hope/src/components/ViewContainer/_view/base.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,3 @@ | ||
import { css } from '@linaria/core'; | ||
|
||
export const base = css``; |
1 change: 1 addition & 0 deletions
1
packages/plasma-new-hope/src/components/ViewContainer/_view/tokens.json
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 @@ | ||
[] |
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 { viewContainerRoot, viewContainerConfig } from './ViewContainer'; |
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
18 changes: 18 additions & 0 deletions
18
.../plasma-new-hope/src/examples/plasma_b2c/components/ViewContainer/ViewContainer.config.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,18 @@ | ||
import { css } from '@linaria/core'; | ||
|
||
// здесь будет импорт непосредственно из темы, например | ||
// import { containerTokens } from '@salutejs/plasma-themes/tokens'; | ||
import { containerTokens } from './tokens'; | ||
|
||
export const config = { | ||
variations: { | ||
view: { | ||
onDark: css` | ||
${containerTokens.onDark} | ||
`, | ||
onLight: css` | ||
${containerTokens.onLight} | ||
`, | ||
}, | ||
}, | ||
}; |
57 changes: 57 additions & 0 deletions
57
...lasma-new-hope/src/examples/plasma_b2c/components/ViewContainer/ViewContainer.stories.tsx
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,57 @@ | ||
import React, { ComponentProps } from 'react'; | ||
import type { StoryObj, Meta } from '@storybook/react'; | ||
|
||
import { WithTheme } from '../../../_helpers'; | ||
import { Heading } from '../../../typograpy/components/Heading/Heading'; | ||
import { Button } from '../../components/Button/Button'; | ||
|
||
import { ViewContainer } from './ViewContainer'; | ||
|
||
type StoryViewProps = ComponentProps<typeof ViewContainer>; | ||
|
||
const meta: Meta<StoryViewProps> = { | ||
title: 'plasma_b2c/ViewContainer', | ||
decorators: [WithTheme], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<StoryViewProps>; | ||
|
||
const backgroundPrimary = '--background-primary'; | ||
const textPrimary = '--text-primary'; | ||
|
||
const ViewExample = ({ view }: StoryViewProps) => { | ||
return ( | ||
<> | ||
<Heading size="h4">view: {view}</Heading> | ||
<div> | ||
<ViewContainer | ||
view={view} | ||
style={{ background: `var(${backgroundPrimary})`, color: `var(${textPrimary})` }} | ||
> | ||
<Heading size="h3">Inside ViewContainer</Heading> | ||
<Button text="default Button" /> | ||
<Button view="accent" text="Accent Button" /> | ||
</ViewContainer> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export const Default: Story = { | ||
render: () => { | ||
return ( | ||
<> | ||
<ViewExample /> | ||
<br /> | ||
<ViewExample view="onDark" /> | ||
<br /> | ||
<ViewExample view="onLight" /> | ||
<br /> | ||
<h3>Inverse in progress</h3> | ||
<br /> | ||
</> | ||
); | ||
}, | ||
}; |
8 changes: 8 additions & 0 deletions
8
packages/plasma-new-hope/src/examples/plasma_b2c/components/ViewContainer/ViewContainer.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,8 @@ | ||
import { viewContainerConfig } from '../../../../components/ViewContainer'; | ||
import { component, mergeConfig } from '../../../../engines'; | ||
|
||
import { config } from './ViewContainer.config'; | ||
|
||
const mergedConfig = mergeConfig(viewContainerConfig, config); | ||
|
||
export const ViewContainer = component(mergedConfig); |
Oops, something went wrong.