Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

refactor(Divider): remove type prop #558

Merged
merged 9 commits into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### BREAKING CHANGES
- `type` prop is replaced with `color` in `Divider` component @layershifter ([#558](https://github.com/stardust-ui/react/pull/558))

### Fixes
- Fix `Provider` is not executing staticStyles with the merged siteVariables @mnajdova ([#559](https://github.com/stardust-ui/react/pull/559))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const items = [
key: 'message-id-4',
},
{
content: <Divider content="Today" type="primary" important />,
content: <Divider content="Today" color="primary" important />,
key: 'message-id-5',
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/src/examples/components/Chat/Types/ChatExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const ChatExample = () => (
/>
</Chat.Item>
<Chat.Item>
<Divider content="Today" type="primary" important />
<Divider content="Today" color="primary" important />
</Chat.Item>
<Chat.Item>
<Chat.Message
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions docs/src/examples/components/Divider/Types/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ const Types = () => (
description="A Divider can contain text or other content displayed alongside with the line."
examplePath="components/Divider/Types/DividerExampleContent"
/>
<ComponentExample
title="Primary divider"
description="A primary Divider catches the user's attention."
examplePath="components/Divider/Types/DividerExamplePrimary"
/>
<ComponentExample
title="Secondary divider"
description="A secondary Divider is more subtle and less noticeable."
examplePath="components/Divider/Types/DividerExampleSecondary"
/>
</ExampleSection>
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ function createMessageContentWithAttachments(content: string, messageId: string)
}

function generateDividerProps(props: DividerProps): Divider {
const { content, important, type = 'secondary' } = props
const dividerProps: Divider = { itemType: ChatItemTypes.divider, content, important, type }
const { content, important, color = 'secondary' } = props
const dividerProps: Divider = { itemType: ChatItemTypes.divider, content, important, color }

return dividerProps
}
Expand Down Expand Up @@ -158,7 +158,7 @@ export function generateChatProps(chat: ChatData): ChatItemContentProps[] {
chatProps.splice(
myLastMsgIndex + 1,
0,
generateDividerProps({ content: 'Last read', type: 'primary', important: true }),
generateDividerProps({ content: 'Last read', color: 'primary', important: true }),
)
}

Expand Down
5 changes: 1 addition & 4 deletions docs/src/views/Theming.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ export default () => (
<ExampleSnippet
render={() => (
<Provider theme={{ siteVariables: { brand: 'hotpink' } }}>
<div>
<Button primary>Branding</Button>
<Divider type="primary">Branding</Divider>
</div>
<Button primary>Branding</Button>
</Provider>
)}
/>
Expand Down
64 changes: 16 additions & 48 deletions docs/src/views/ThemingExamples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default () => (
<ExampleSnippet
value={`
import React from 'react'
import { Button, Divider, Icon, Label, Provider } from '@stardust-ui/react'
import { Button, Icon, Label, Provider } from '@stardust-ui/react'

export default () =>
<Provider>
Expand All @@ -54,9 +54,6 @@ export default () => (
<Button icon="at" content="Send email" secondary />
<Icon name="chess rook" size="big" />
<Label content="Label with icon" icon="close" />
<br/><br/>
<Divider content="Primary Divider" type="primary" />
<Divider content="Secondary Divider" type="secondary" />
</>
</Provider>
`}
Expand All @@ -67,10 +64,6 @@ export default () => (
<Button icon="at" content="Send email" secondary />
<Icon name="chess rook" size="big" />
<Label content="Label with icon" icon="close" />
<br />
<br />
<Divider content="Primary Divider" type="primary" />
<Divider content="Secondary Divider" type="secondary" />
</>
)}
/>
Expand All @@ -90,20 +83,21 @@ export default () => (
import { Button } from '@stardust-ui/react'

const styles = {
color: "coral",
backgroundColor: "coral",
fontSize: "14px",
padding: "0 10px",
}
color: "coral",
backgroundColor: "coral",
fontSize: "14px",
padding: "0 10px",
}
const btnExample = () =>
<Button
content="Send email"
icon={{
name: "at",
styles: { color: "brown" },
}}
secondary
styles={styles} />
<Button
content="Send email"
icon={{
name: "at",
styles: { color: "brown" },
}}
secondary
styles={styles}
/>

export default btnExample
`}
Expand Down Expand Up @@ -187,7 +181,7 @@ export default () => (
<ExampleSnippet
value={`
import React from 'react'
import { Button, Divider, Icon, Label, Provider } from '@stardust-ui/react'
import { Button, Icon, Label, Provider } from '@stardust-ui/react'

const theme = {
siteVariables: {
Expand Down Expand Up @@ -226,9 +220,6 @@ export default () => (
<Button icon="at" content="Send email" secondary />
<Icon name="chess rook" size="big" />
<Label content="Label with icon" icon="close" />
<br /><br />
<Divider type="primary">Branding primary</Divider>
<Divider type="secondary">Branding secondary</Divider>
</div>
</Provider>
)
Expand Down Expand Up @@ -273,10 +264,6 @@ export default () => (
<Button icon="at" content="Send email" secondary />
<Icon name="chess rook" size="big" />
<Label content="Label with icon" icon="close" />
<br />
<br />
<Divider content="Primary Divider" type="primary" />
<Divider content="Secondary Divider" type="secondary" />
</div>
</Provider>
</div>
Expand All @@ -294,7 +281,6 @@ export default () => (
/* Default theming */
<Header as="h3" content="Default" />
<Button primary>Branding</Button>
<Divider type="primary">Branding</Divider>

/* First nested theming */
<Provider
Expand All @@ -310,9 +296,6 @@ export default () => (
<Button icon="at" content="Send email" secondary />
<Icon name="chess rook" size="big" />
<Label content="Label with icon" icon="close" />
<br/><br/>
<Divider content="Primary Divider" type="primary" />
<Divider content="Secondary Divider" type="secondary" />

/* Second nested theming */
<Provider
Expand All @@ -332,9 +315,6 @@ export default () => (
<Button icon="at" content="Send email" secondary />
<Icon name="chess rook" size="big" />
<Label content="Label with icon" icon="close" />
<br/><br/>
<Divider content="Primary Divider" type="primary" />
<Divider content="Secondary Divider" type="secondary" />
</div>
</Provider>
</div>
Expand All @@ -349,10 +329,6 @@ export default () => (
<Button icon="at" content="Send email" secondary />
<Icon name="chess rook" size="big" />
<Label content="Label with icon" icon="close" />
<br />
<br />
<Divider content="Primary Divider" type="primary" />
<Divider content="Secondary Divider" type="secondary" />

<Provider
theme={{
Expand All @@ -367,10 +343,6 @@ export default () => (
<Button icon="at" content="Send email" secondary />
<Icon name="chess rook" size="big" />
<Label content="Label with icon" icon="close" />
<br />
<br />
<Divider content="Primary Divider" type="primary" />
<Divider content="Secondary Divider" type="secondary" />

<Provider
theme={{
Expand All @@ -389,10 +361,6 @@ export default () => (
<Button icon="at" content="Send email" secondary />
<Icon name="chess rook" size="big" />
<Label content="Label with icon" icon="close" />
<br />
<br />
<Divider content="Primary Divider" type="primary" />
<Divider content="Secondary Divider" type="secondary" />
</>
</Provider>
</>
Expand Down
4 changes: 0 additions & 4 deletions src/components/Divider/Divider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ export interface DividerProps
/** Size multiplier (default 0) * */
size?: number

/** A Divider can be formatted to show different levels of emphasis. */
type?: 'primary' | 'secondary'

/** A divider can appear more important and draw the user's attention. */
important?: boolean
}
Expand All @@ -45,7 +42,6 @@ class Divider extends UIComponent<Extendable<DividerProps>, any> {
...commonPropTypes.createCommon({ color: true }),
fitted: PropTypes.bool,
size: PropTypes.number,
type: PropTypes.oneOf(['primary', 'secondary']),
important: PropTypes.bool,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { DividerVariables } from '../../../teams/components/Divider/dividerVaria
import { Partial } from 'types/utils'

export default (siteVars: any): Partial<DividerVariables> => ({
primaryColor: siteVars.brand06,
colors: {
primary: siteVars.brand06,
},
textColor: siteVars.gray02,
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { DividerVariables } from '../../../teams/components/Divider/dividerVaria
import { Partial } from 'types/utils'

export default (siteVars: any): Partial<DividerVariables> => ({
colors: {
primary: siteVars.white,
},
dividerColor: siteVars.white,
textColor: siteVars.white,
primaryColor: siteVars.white,
})
10 changes: 2 additions & 8 deletions src/themes/teams/components/Divider/dividerStyles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ const beforeAndAfter = (color, size, type, variables): ICSSPseudoElementStyle =>
flex: 1,
...dividerBorderStyle(size, variables.dividerColor),
...(color && {
...dividerBorderStyle(size, _.get(variables.colors, [color, 500])),
}),
...(type === 'primary' && {
...dividerBorderStyle(size, variables.primaryColor),
...dividerBorderStyle(size, _.get(variables.colors, color)),
}),
})

Expand All @@ -33,10 +30,7 @@ const dividerStyles: ComponentSlotStylesInput<DividerPropsWithDefaults, any> = {
paddingBottom: variables.dividerPadding,
}),
...(color && {
color: _.get(variables.colors, [color, 500]),
}),
...(type === 'primary' && {
color: variables.primaryColor,
color: _.get(variables.colors, color),
}),
...(important && {
fontWeight: variables.importantFontWeight,
Expand Down
10 changes: 6 additions & 4 deletions src/themes/teams/components/Divider/dividerVariables.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import * as _ from 'lodash'

import { EmphasisColors, NaturalColors } from '../../../types'
import { pxToRem } from '../../../../lib'

export interface DividerVariables {
colors: EmphasisColors & NaturalColors
colors: Record<keyof (EmphasisColors & NaturalColors), string>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL: Record

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@layershifter can we extract this interface
Record<keyof (EmphasisColors & NaturalColors), string>
in src/themes/types.ts to reuse it for other's components color prop?

dividerColor: string
textColor: string
textFontSize: string
textLineHeight: string
primaryColor: string
importantFontWeight: string
dividerPadding: string
}

export default (siteVars: any): DividerVariables => {
const colorVariant = '500'

return {
colors: { ...siteVars.emphasisColors, ...siteVars.naturalColors },
colors: _.mapValues({ ...siteVars.emphasisColors, ...siteVars.naturalColors }, colorVariant),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@layershifter can we extract this method
_.mapValues({ ...siteVars.emphasisColors, ...siteVars.naturalColors }, colorVariant),
or even an object if the colorVariant is always 500
export themeColors = _.mapValues({ ...siteVars.emphasisColors, ...siteVars.naturalColors }, 500)
to reuse it for other's components color prop?

dividerColor: siteVars.gray09,
textColor: siteVars.gray03,
textFontSize: siteVars.fontSizeSmall,
textLineHeight: siteVars.lineHeightSmall,
primaryColor: siteVars.brand,
importantFontWeight: siteVars.fontWeightBold,
dividerPadding: pxToRem(4),
}
Expand Down