Skip to content

Commit

Permalink
Merge branch 'master' into add-keydown-textarea
Browse files Browse the repository at this point in the history
  • Loading branch information
jennyscript committed Aug 20, 2018
2 parents 8308a07 + 914500f commit 4d83201
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Internal: Turn on sketchy-number flow lint rules as an error (#293)
* TextArea: Add an onKeyDown prop (#303)
* TextField: Add an onKeyDown prop (#303)
* Internal: Add flow types to `Box` transform functors (#299)
* Icon: Fix cog icon rotation (#308)

### Patch
Expand Down
2 changes: 0 additions & 2 deletions packages/gestalt/src/Box.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ import {
toProps,
} from './style.js';
import {
// flowlint untyped-import:off
union,
bind,
range,
toggle,
mapping,
rangeWithoutZero,
// flowlint untyped-import:error
} from './transforms.js';

/*
Expand Down
2 changes: 1 addition & 1 deletion packages/gestalt/src/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type InlineStyle = { [key: string]: string | number | void };

// TODO: This type should be opaque, however the Babel parser doesn't support
// the opaque syntax yet.
type Style = {|
export type Style = {|
className: Set<string>,
inlineStyle: InlineStyle,
|};
Expand Down
28 changes: 20 additions & 8 deletions packages/gestalt/src/transforms.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { concat, fromClassName, identity, mapClassName } from './style.js';
// @flow

import {
concat,
fromClassName,
identity,
mapClassName,
type Style,
} from './style.js';

/*
Expand All @@ -8,18 +16,20 @@ These are a collection of a few functors that take values and returns Style's. O
*/

type Functor = (n: number) => Style;

// Adds a classname when a property is present.
//
// <Box top />
//
export const toggle = (...classNames) => val =>
export const toggle = (...classNames: Array<string>) => (val?: boolean) =>
val ? fromClassName(...classNames) : identity();

// Maps string values to classes
//
// <Box alignItems="center" />
//
export const mapping = map => val =>
export const mapping = (map: { [key: string]: string }) => (val: string) =>
Object.prototype.hasOwnProperty.call(map, val)
? fromClassName(map[val])
: identity();
Expand All @@ -28,22 +38,24 @@ export const mapping = map => val =>
//
// <Box padding={1} />
//
export const range = scale => n =>
export const range = (scale: string) => (n: number) =>
fromClassName(`${scale}${n < 0 ? `N${Math.abs(n)}` : n}`);

// Like `range`, maps a range of integers to a range of classnames, excluding
// zero values.
//
// <Box padding={0} />
export const rangeWithoutZero = scale => n =>
export const rangeWithoutZero = (scale: string) => (n: number) =>
n === 0 ? identity() : range(scale)(n);

// Binds a string classname to the value in an object. Useful when interacting
// with ranges that need to come dynamically from a style object. This is
// similar to the NPM package 'classnames/bind'.
export const bind = (fn, scope) => val =>
mapClassName(name => scope[name])(fn(val));
export const bind = (fn: Functor, scope: { [key: string]: string }) => (
val: number
) => mapClassName(name => scope[name])(fn(val));

// This takes a series of the previously defined functors, runs them all
// against a value and returns the set of their classnames.
export const union = (...fns) => val => concat(fns.map(fn => fn(val)));
export const union = (...fns: Array<Functor>) => (val: number) =>
concat(fns.map(fn => fn(val)));

0 comments on commit 4d83201

Please sign in to comment.