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
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
7 changes: 6 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ jobs:
- run:
name: Prettier
command: yarn prettier
# weak package is required for --detectLeaks in Unit tests
# it is not in package.json as it would require Python on Windows
- run:
name: Install weak
command: yarn add --dev weak
- run:
name: Unit Tests
command: yarn test --strict --maxWorkers=4
command: yarn test --strict --maxWorkers=4 --detectLeaks
- run:
name: Report coverage
command: bash <(curl -s https://codecov.io/bash)
Expand Down
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Fixes
- Fix focus outline visible only during keyboard navigation in `ListItem` @layershifter ([#727](https://github.com/stardust-ui/react/pull/727))
- Pass `jest --detectLeaks` tests @miroslavstastny ([#718](https://github.com/stardust-ui/react/pull/718))
- Fix Avatar's size example @mnajdova ([#745](https://github.com/stardust-ui/react/pull/745))

### Features
Expand All @@ -35,15 +36,15 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Fixes
- Remove `render` from default factories options @layershifter ([#735](https://github.com/stardust-ui/react/pull/735))

### Features
- Add accessibility for submenu in toolbar and menu behavior @kolaps33 ([#686](https://github.com/stardust-ui/react/pull/686))

### Documentation
- Fix ignored initial state of knobs @layershifter ([#720](https://github.com/stardust-ui/react/pull/720))
- Fix unclearable example's code @layershifter ([#720](https://github.com/stardust-ui/react/pull/720))
- Add ability to export examples to CodeSandbox @layershifter ([#731](https://github.com/stardust-ui/react/pull/731))
- Fix remove empty item in docs sidebar @layershifter ([#728](https://github.com/stardust-ui/react/pull/728))

### Features
- Add accessibility for submenu in toolbar and menu behavior @kolaps33 ([#686](https://github.com/stardust-ui/react/pull/686))

<!--------------------------------[ v0.16.2 ]------------------------------- -->
## [v0.16.2](https://github.com/stardust-ui/react/tree/v0.16.2) (2019-01-14)
[Compare changes](https://github.com/stardust-ui/react/compare/v0.16.1...v0.16.2)
Expand All @@ -54,8 +55,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Add `accessibility` and `styles` to the API of `createComponent` @kuzhelov ([#714](https://github.com/stardust-ui/react/pull/714))

### Fixes
- Fix doc layout for Menu component @codepretty ([#695] https://github.com/stardust-ui/react/pull/695)
- Fix focus outline visible only during keyboard navigation @kolaps33 ([#689] https://github.com/stardust-ui/react/pull/689)
- Fix doc layout for Menu component @codepretty ([#695](https://github.com/stardust-ui/react/pull/695))
- Fix focus outline visible only during keyboard navigation @kolaps33 ([#689](https://github.com/stardust-ui/react/pull/689))
- Fix handling changes of `renderer` prop in `Provider` @layershifter ([#702](https://github.com/stardust-ui/react/pull/702))
- Fix Menu themeing styles @codepretty ([#708](https://github.com/stardust-ui/react/pull/708))
- Prevent infinite rendering loop start on `Popup` open @kuzhelov ([#705](https://github.com/stardust-ui/react/pull/705))
Expand Down
1 change: 1 addition & 0 deletions build/gulp/tasks/test-unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const jest = ({ watch = false } = {}) => cb => {
watch && '--watchAll',
argv.runInBand && '--runInBand',
argv.maxWorkers && `--maxWorkers=${argv.maxWorkers}`,
argv.detectLeaks && '--detectLeaks',
]
.filter(Boolean)
.join(' ')
Expand Down
6 changes: 3 additions & 3 deletions docs/src/components/ExternalExampleLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _ from 'lodash/fp'
import * as _ from 'lodash'
import * as PropTypes from 'prop-types'
import * as React from 'react'
import SourceRender from 'react-source-render'
Expand All @@ -18,10 +18,10 @@ const ExternalExampleLayout: any = props => {
const { exampleName } = props.match.params
const exampleFilename = exampleKebabNameToSourceFilename(exampleName)

const examplePath = _.find(path => {
const examplePath = _.find(examplePaths, path => {
const { exampleName } = parseExamplePath(path)
return exampleFilename === exampleName
}, examplePaths)
})

if (!examplePath) return <PageNotFound />
const exampleSource: ExampleSource = exampleSourcesContext(examplePath)
Expand Down
24 changes: 12 additions & 12 deletions docs/src/components/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import keyboardKey from 'keyboard-key'
import * as _ from 'lodash/fp'
import * as _ from 'lodash'
import * as PropTypes from 'prop-types'
import * as React from 'react'
import { findDOMNode } from 'react-dom'
Expand Down Expand Up @@ -102,10 +102,10 @@ class Sidebar extends React.Component<any, any> {
}
}

private menuItemsByType = _.map(nextType => {
const items = _.flow(
_.filter<ComponentMenuItem>(({ type }) => type === nextType),
_.map(info => (
private menuItemsByType = _.map(constants.typeOrder, nextType => {
const items = _.chain([...componentMenu, ...behaviorMenu])
.filter(({ type }) => type === nextType)
.map(info => (
<Menu.Item
key={info.displayName}
name={info.displayName}
Expand All @@ -114,16 +114,16 @@ class Sidebar extends React.Component<any, any> {
to={getComponentPathname(info)}
activeClassName="active"
/>
)),
)([...componentMenu, ...behaviorMenu])
))
.value()

return (
<Menu.Item key={nextType}>
<Menu.Header>{_.capitalize(nextType)}s</Menu.Header>
<Menu.Menu>{items}</Menu.Menu>
</Menu.Item>
)
}, constants.typeOrder)
})

private renderSearchItems = () => {
const { selectedItemIndex, query } = this.state
Expand All @@ -134,16 +134,16 @@ class Sidebar extends React.Component<any, any> {
const containsMatches: ComponentMenuItem[] = []
const escapedQuery = _.escapeRegExp(query)

_.each(info => {
_.each(componentMenu, info => {
if (new RegExp(`^${escapedQuery}`, 'i').test(info.displayName)) {
startsWithMatches.push(info)
} else if (new RegExp(escapedQuery, 'i').test(info.displayName)) {
containsMatches.push(info)
}
}, componentMenu)
})

this.filteredMenu = [...startsWithMatches, ...containsMatches]
const menuItems = _.map(info => {
const menuItems = _.map(this.filteredMenu, info => {
itemIndex += 1
const isSelected = itemIndex === selectedItemIndex

Expand All @@ -162,7 +162,7 @@ class Sidebar extends React.Component<any, any> {
{isSelected && selectedItemLabel}
</Menu.Item>
)
}, this.filteredMenu)
})

return <Menu.Menu>{menuItems}</Menu.Menu>
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/utils/examplePathToHash.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _ from 'lodash/fp'
import * as _ from 'lodash'
import parseExamplePath from './parseExamplePath'

/**
Expand Down
63 changes: 31 additions & 32 deletions src/lib/customPropTypes.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import * as _ from 'lodash/fp'
import * as _ from 'lodash'
import * as PropTypes from 'prop-types'
import leven from './leven'
import { ObjectOf } from '../../types/utils'

type SuggestProps = { score: number; suggestion: string }

const typeOf = x => Object.prototype.toString.call(x)

/**
Expand Down Expand Up @@ -39,27 +37,27 @@ export const suggest = (suggestions: string[]) => {
const findBestSuggestions = _.memoize((str: string) => {
const propValueWords = str.split(' ')

return _.flow(
_.map((suggestion: string) => {
return _.chain(suggestions)
Copy link
Member

Choose a reason for hiding this comment

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

Heads up that _.chain causes all (or almost all) of lodash to be imported because all the chainable functions must be available on the returned object, and lodash can't statically detect which will be used (i.e. tree shaking will not work). Recommend refactoring to reduce the weight of our library.

https://medium.com/making-internets/why-using-chain-is-a-mistake-9bc1f80d51ba

.map((suggestion: string) => {
const suggestionWords = suggestion.split(' ')

const propValueScore = _.flow(
_.map(x => _.map(y => leven(x, y), suggestionWords)),
_.map(_.min),
_.sum,
)(propValueWords)
const propValueScore = _.chain(propValueWords)
.map(x => _.map(suggestionWords, y => leven(x, y)))
.map(_.min)
.sum()
.value()

const suggestionScore = _.flow(
_.map(x => _.map(y => leven(x, y), propValueWords)),
_.map(_.min),
_.sum,
)(suggestionWords)
const suggestionScore = _.chain(suggestionWords)
.map(x => _.map(propValueWords, y => leven(x, y)))
.map(_.min)
.sum()
.value()

return { suggestion, score: propValueScore + suggestionScore }
}),
_.sortBy<SuggestProps>(['score', 'suggestion']),
_.take(3),
)(suggestions)
})
.sortBy(['score', 'suggestion'])
.take(3)
.value()
})

// Convert the suggestions list into a hash map for O(n) lookup times. Ensure
Expand Down Expand Up @@ -170,20 +168,20 @@ export const every = (validators: Function[]) => (
)
}

const errors = _.flow(
_.map(validator => {
const error = _.chain(validators)
.map(validator => {
if (typeof validator !== 'function') {
throw new Error(
`every() argument "validators" should contain functions, found: ${typeOf(validator)}.`,
)
}
return validator(props, propName, componentName, ...args)
}),
_.compact,
)(validators)
})
.compact()
.first() // we can only return one error at a time
.value()

// we can only return one error at a time
return errors[0]
return error
}

/**
Expand All @@ -205,21 +203,22 @@ export const some = (validators: Function[]) => (
)
}

const errors = _.compact(
_.map(validator => {
const errors = _.chain(validators)
.map(validator => {
if (!_.isFunction(validator)) {
throw new Error(
`some() argument "validators" should contain functions, found: ${typeOf(validator)}.`,
)
}
return validator(props, propName, componentName, ...args)
}, validators),
)
})
.compact()
.value()

// fail only if all validators failed
if (errors.length === validators.length) {
const error = new Error('One of these validators must pass:')
error.message += `\n${_.map(err => `- ${err.message}`, errors).join('\n')}`
error.message += `\n${_.map(errors, err => `- ${err.message}`).join('\n')}`
return error
}

Expand Down Expand Up @@ -269,7 +268,7 @@ export const givenProps = (propsShape: object, validator: Function) => (

if (error) {
// poor mans shallow pretty print, prevents JSON circular reference errors
const prettyProps = `{ ${_.keys(_.pick(_.keys(propsShape), props))
const prettyProps = `{ ${_.keys(_.pick(props, _.keys(propsShape)))
.map(key => {
const val = props[key]
let renderedValue = val
Expand Down