Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d368f8d
-added new theme
Sep 24, 2018
f15bbf9
-added docs page theme switcher
Sep 26, 2018
c094e36
-added examples for teams dark and teams high contrast themes
Sep 26, 2018
3ed0545
-fixed not needed re-rendering when the theme is not changed
Sep 26, 2018
27cf9d1
-simplifying the high contrast theme
Sep 26, 2018
fa1bec0
-simplifying dark and high contrast theme
Sep 26, 2018
be911d7
-improved styles for the theme picker dropdown
Sep 26, 2018
4dcbc30
-tslint fixes
Sep 26, 2018
0a67747
Merge branch 'master' into feat/theme-switcher
Sep 26, 2018
6455358
Merge branch 'master' into feat/theme-switcher
Sep 27, 2018
e18b8fc
-moves the merging of the themes from the Provider ot the exporting f…
Sep 27, 2018
cf9c277
-exported just the merged themes
Sep 27, 2018
cfd9dac
-exported standalone themes (dark and HC)
Sep 27, 2018
d6ccfb3
Merge branch 'master' into feat/theme-switcher
levithomason Sep 27, 2018
a62497e
cleanup sidebar
levithomason Sep 27, 2018
a032a55
cleanup dark/contrast theme values
levithomason Sep 29, 2018
e81677a
-added dev mode decorator for the theme switching
Oct 1, 2018
6d35bb3
Merge branch 'master' into feat/theme-switcher
Oct 1, 2018
2933d8f
-removing static styles for the semantic ui dropdown
Oct 1, 2018
de34860
Merge branch 'master' into feat/theme-switcher
Oct 1, 2018
090364b
-fixing issue with changing body font size
Oct 1, 2018
e7d7ca3
-removing unused variables
Oct 1, 2018
efdc0af
-ComponentExample: state's componentVariables now holds just the vari…
Oct 2, 2018
60c8720
-replaced mobx with react context API
Oct 2, 2018
a08e6b7
-reverted tsconfig to the initial version
Oct 2, 2018
94f5942
Merge branch 'master' into feat/theme-switcher
Oct 2, 2018
9a71f3d
Merge branch 'master' into feat/theme-switcher
Oct 3, 2018
6f91a46
-updated changelog
Oct 3, 2018
426fd71
-merging two lines
Oct 3, 2018
68eb2b1
-introduced app component as a root for the docs
Oct 3, 2018
7e4835b
Merge branch 'master' into feat/theme-switcher
Oct 3, 2018
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 @@ -25,6 +25,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add focus styles for `Menu.Item` component @Bugaa92 ([#286](https://github.com/stardust-ui/react/pull/286))
- Add keyboard handling and ARIA attributes for `ButtonGroup`, `Tablist` and `Toolbar` behaviors @jurokapsiar ([#254](https://github.com/stardust-ui/react/pull/254))

### Documentation
- Add theme switcher for exploring different themes on the docs (under development mode flag) @mnajdova ([#280](https://github.com/stardust-ui/react/pull/280))

<!--------------------------------[ v0.8.0 ]------------------------------- -->
## [v0.8.0](https://github.com/stardust-ui/react/tree/v0.8.0) (2018-10-01)
[Compare changes](https://github.com/stardust-ui/react/compare/v0.7.0...v0.8.0)
Expand Down
2 changes: 1 addition & 1 deletion build/tsconfig.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "./tsconfig.common.json",
"compilerOptions": {
"module": "esnext",
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true
},
"include": [
"../src",
Expand Down
57 changes: 57 additions & 0 deletions docs/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as React from 'react'
import { Provider, themes } from '@stardust-ui/react'

import { mergeThemes } from '../../src/lib'
import { semanticCssOverrides } from './Style'
import { ThemeContext } from './context/theme-context'
import Router from './routes'

const semanticStyleOverrides = {
staticStyles: [semanticCssOverrides],
}

interface IAppState {
themeName: string
changeTheme: (newTheme: string) => void
}

class App extends React.Component<any, IAppState> {
private changeTheme

constructor(props) {
super(props)

this.changeTheme = newTheme => {
this.setState({
themeName: newTheme,
})
}

// State also contains the updater function so it will
// be passed down into the context provider
this.state = {
themeName: 'teams',
changeTheme: this.changeTheme,
}
}
render() {
const { themeName } = this.state
return (
<ThemeContext.Provider value={this.state}>
<Provider
theme={mergeThemes(semanticStyleOverrides, themes[themeName], {
// adjust Teams' theme to Semantic UI's font size scheme
siteVariables: {
htmlFontSize: '14px',
bodyFontSize: '1rem',
},
})}
>
<Router />
</Provider>
</ThemeContext.Provider>
)
}
}

export default App
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as _ from 'lodash'
import PropTypes from 'prop-types'
import * as React from 'react'
import { withRouter, RouteComponentProps } from 'react-router'
import { RouteComponentProps, withRouter } from 'react-router'
import { renderToStaticMarkup } from 'react-dom/server'
import { html } from 'js-beautify'
import * as copyToClipboard from 'copy-to-clipboard'
Expand All @@ -23,17 +23,21 @@ import ComponentExampleTitle from './ComponentExampleTitle'
import ContributionPrompt from '../ContributionPrompt'
import getSourceCodeManager, { ISourceCodeManager, SourceCodeType } from './SourceCodeManager'
import { IThemeInput, IThemePrepared } from 'types/theme'
import { mergeThemeVariables } from '../../../../../src/lib/mergeThemes'
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

import { ThemeContext } from '../../../context/theme-context'

export interface IComponentExampleProps extends RouteComponentProps<any, any> {
title: string
description: string
examplePath: string
suiVersion?: string
themeName?: string
}

interface IComponentExampleState {
knobs: Object
theme: IThemeInput
themeName: string
componentVariables: Object
exampleElement?: JSX.Element
handleMouseLeave?: () => void
handleMouseMove?: () => void
Expand Down Expand Up @@ -62,7 +66,7 @@ const codeTypeApiButtonLabels: { [key in SourceCodeType]: string } = {
* Renders a `component` and the raw `code` that produced it.
* Allows toggling the the raw `code` code block.
*/
class ComponentExample extends React.PureComponent<IComponentExampleProps, IComponentExampleState> {
class ComponentExample extends React.Component<IComponentExampleProps, IComponentExampleState> {
private componentRef: React.Component
private sourceCodeMgr: ISourceCodeManager
private anchorName: string
Expand All @@ -71,7 +75,8 @@ class ComponentExample extends React.PureComponent<IComponentExampleProps, IComp

public state: IComponentExampleState = {
knobs: {},
theme: themes.teams,
themeName: 'teams',
componentVariables: {},
sourceCode: '',
markup: '',
showCode: false,
Expand All @@ -95,6 +100,7 @@ class ComponentExample extends React.PureComponent<IComponentExampleProps, IComp
match: PropTypes.object.isRequired,
suiVersion: PropTypes.string,
title: PropTypes.node,
themeName: PropTypes.string,
}

public componentWillMount() {
Expand Down Expand Up @@ -123,6 +129,10 @@ class ComponentExample extends React.PureComponent<IComponentExampleProps, IComp
) {
this.clearActiveState()
}
const { themeName } = nextProps
if (this.state.themeName !== themeName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

a bit unsure - do we really need to store themeName as state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, this was changed when the name of the theme was fetch from the mobx store, the themeName prop should be enough now. Will change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I got it now. This was added because we want to invoke renderSourceCode if the themeName prop is changed. Since we are invoking this method here, we need to have a way to get the new themeName, that's why I have it in the state as well. Any other idea about how can we achive this?

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, yes - but just to unblock the PR, we could make a notch, merge it and I will try to experiment on that further. To me themeName has clear immutable semantics (that is not example-specific - and this is a key difference from other ones, like showRtl, for example), so this is the reason I'd rather see it being introduced as prop

this.setState({ themeName }, this.renderSourceCode)
}
}

private clearActiveState = () => {
Expand Down Expand Up @@ -346,10 +356,13 @@ class ComponentExample extends React.PureComponent<IComponentExampleProps, IComp
private getDisplayName = () => this.props.examplePath.split('/')[1]

private renderWithProvider(ExampleComponent) {
const { showRtl, theme } = this.state
const { showRtl, componentVariables, themeName } = this.state
const theme = themes[themeName]

const newTheme: IThemeInput = {
componentVariables: theme.componentVariables,
componentVariables: mergeThemeVariables(theme.componentVariables, {
[this.getDisplayName()]: componentVariables,
}),
rtl: showRtl,
}

Expand Down Expand Up @@ -540,7 +553,10 @@ class ComponentExample extends React.PureComponent<IComponentExampleProps, IComp
</Divider>
<Provider.Consumer
render={({ siteVariables, componentVariables }: IThemePrepared) => {
const variables = componentVariables[displayName]
const mergedVariables = mergeThemeVariables(componentVariables, {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we merge them again here? May be missing something, but it seems that we already merged these variables on line 364, so they will be consumed as already merged ones

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It took me also lot of time to figure this out, but this consumer is for the root Theme Provider, where in contrast, the example, uses it's own provider where these are merged (overriden). This is why we actually have previously bug where the componentVariables were not reflecting the latest status of the variables applied on the example.

Copy link
Contributor

Choose a reason for hiding this comment

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

got it - still, see it to be a problem that we are merging in two different places of the ComponentExample code. Let me take a look on that after PR will be merged

[displayName]: this.state.componentVariables,
})
const variables = mergedVariables[displayName]

if (!variables) {
return (
Expand Down Expand Up @@ -580,15 +596,9 @@ class ComponentExample extends React.PureComponent<IComponentExampleProps, IComp
private handleVariableChange = (component, variable) => (e, { value }) => {
this.setState(
state => ({
theme: {
...state.theme,
componentVariables: {
...state.theme.componentVariables,
[component]: {
...(state.theme.componentVariables && state.theme.componentVariables[component]),
[variable]: value,
},
},
componentVariables: {
...state.componentVariables,
[variable]: value,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kuzhelov please take a look into the changes in this file regarding the componentVariables. It seems to work okay in my opinion, but would like to have your approval on this, as the initial changes were yours. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

these changes were made at the moment where there were no mergeThemeVariables yet - now we should rather reuse this functionality here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed the state's componentVariable to store just the variables for the component being rendered, and then I am using the mergeThemeVariables for generating the final componentVariables. Please take a look now.

}),
this.renderSourceCode,
Expand Down Expand Up @@ -697,4 +707,10 @@ class ComponentExample extends React.PureComponent<IComponentExampleProps, IComp
}
}

export default withRouter(ComponentExample)
const ComponentExampleWithTheme = React.forwardRef((props: IComponentExampleProps) => (
<ThemeContext.Consumer>
{({ themeName }) => <ComponentExample {...props} themeName={themeName} />}
</ThemeContext.Consumer>
))

export default withRouter(ComponentExampleWithTheme)
143 changes: 87 additions & 56 deletions docs/src/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import * as React from 'react'
import { findDOMNode } from 'react-dom'
import { NavLink } from 'react-router-dom'
import { withRouter } from 'react-router'
import { Menu, Icon, Input as SemanticUIInput } from 'semantic-ui-react'
import { Icon, Input as SemanticUIInput, Menu } from 'semantic-ui-react'

import Logo from 'docs/src/components/Logo/Logo'
import { getComponentPathname, typeOrder, repoURL } from 'docs/src/utils'
import { getComponentPathname, repoURL, typeOrder } from 'docs/src/utils'
import { themes } from '@stardust-ui/react'
import { ThemeContext } from '../../context/theme-context'

const pkg = require('../../../../package.json')
const componentMenu = require('docs/src/componentMenu')
Expand Down Expand Up @@ -167,66 +169,95 @@ class Sidebar extends React.Component<any, any> {
const { style } = this.props
const { query } = this.state
return (
<Menu vertical fixed="left" inverted style={{ ...style }}>
<Menu.Item>
<Logo spaced="right" size="mini" />
<strong>
Stardust UI React &nbsp;
<small>
<em>{pkg.version}</em>
</small>
</strong>
<Menu.Menu>
<Menu.Item as="a" href={repoURL} target="_blank" rel="noopener noreferrer">
<Icon name="github" /> GitHub
<ThemeContext.Consumer>
{({ themeName, changeTheme }) => (
<Menu vertical fixed="left" inverted style={{ ...style }}>
<Menu.Item>
<Logo spaced="right" size="mini" />
<strong>
Stardust UI React &nbsp;
<small>
<em>{pkg.version}</em>
</small>
</strong>
<Menu.Menu>
<Menu.Item as="a" href={repoURL} target="_blank" rel="noopener noreferrer">
<Icon name="github" /> GitHub
</Menu.Item>
<Menu.Item
as="a"
href={`${repoURL}/blob/master/CHANGELOG.md`}
target="_blank"
rel="noopener noreferrer"
>
<Icon name="file alternate outline" /> CHANGELOG
</Menu.Item>
</Menu.Menu>
</Menu.Item>
<Menu.Item
as="a"
href={`${repoURL}/blob/master/CHANGELOG.md`}
target="_blank"
rel="noopener noreferrer"
>
<Icon name="file alternate outline" /> CHANGELOG
{process.env.NODE_ENV !== 'production' && (
<Menu.Item>
<p>Theme:</p>
<select
placeholder="Select theme..."
defaultValue={themeName}
onChange={e => {
changeTheme(e.target.value)
}}
>
{this.getThemeOptions().map(o => (
<option key={o.value} value={o.value}>
{o.text}
</option>
))}
</select>
</Menu.Item>
)}
<Menu.Item as={NavLink} exact to="/" activeClassName="active">
Introduction
</Menu.Item>
</Menu.Menu>
</Menu.Item>
<Menu.Item as={NavLink} exact to="/" activeClassName="active">
Introduction
</Menu.Item>
<Menu.Item>
Guides
<Menu.Menu>
<Menu.Item as={NavLink} exact to="/quick-start" activeClassName="active">
Quick Start
</Menu.Item>
<Menu.Item as={NavLink} exact to="/glossary" activeClassName="active">
Glossary
</Menu.Item>
<Menu.Item as={NavLink} exact to="/accessibility" activeClassName="active">
Accessibility
</Menu.Item>
<Menu.Item as={NavLink} exact to="/theming" activeClassName="active">
Theming
<Menu.Item>
Guides
<Menu.Menu>
<Menu.Item as={NavLink} exact to="/quick-start" activeClassName="active">
Quick Start
</Menu.Item>
<Menu.Item as={NavLink} exact to="/glossary" activeClassName="active">
Glossary
</Menu.Item>
<Menu.Item as={NavLink} exact to="/accessibility" activeClassName="active">
Accessibility
</Menu.Item>
<Menu.Item as={NavLink} exact to="/theming" activeClassName="active">
Theming
</Menu.Item>
<Menu.Item as={NavLink} exact to="/theming-examples" activeClassName="active">
Theming Examples
</Menu.Item>
</Menu.Menu>
</Menu.Item>
<Menu.Item as={NavLink} exact to="/theming-examples" activeClassName="active">
Theming Examples
<Menu.Item active>
<SemanticUIInput
className="transparent inverted icon"
icon="search"
placeholder="Search components..."
value={query}
onChange={this.handleSearchChange}
onKeyDown={this.handleSearchKeyDown}
/>
</Menu.Item>
</Menu.Menu>
</Menu.Item>
<Menu.Item active>
<SemanticUIInput
className="transparent inverted icon"
icon="search"
placeholder="Search components..."
value={query}
onChange={this.handleSearchChange}
onKeyDown={this.handleSearchKeyDown}
/>
</Menu.Item>
{query ? this.renderSearchItems() : this.menuItemsByType}
</Menu>
{query ? this.renderSearchItems() : this.menuItemsByType}
</Menu>
)}
</ThemeContext.Consumer>
)
}

private getThemeOptions = () => {
return Object.keys(themes).map(key => ({
text: _.startCase(key),
value: key,
}))
}
}

export default withRouter(Sidebar)
6 changes: 6 additions & 0 deletions docs/src/context/theme-context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as React from 'react'

export const ThemeContext = React.createContext({
themeName: 'teams',
changeTheme: (newTheme: string) => {},
})
Loading