Skip to content
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
64 changes: 64 additions & 0 deletions src/Choice Tile/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import classNames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';

import { SIZES } from '../constants';
import { wcBool } from '../utils';

const ChoiceTile = ({
checked,
children,
className,
disabled,
icon,
invalid,
name,
onChange,
size,
subdued,
title,
...rest
}) => {
return (
<label className={classNames({ hxChoice: true, className })}>
Copy link
Contributor

Choose a reason for hiding this comment

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

non blocking: a potential shorter way to say the same thing:

Suggested change
<label className={classNames({ hxChoice: true, className })}>
<label className={classNames( 'hxChoice', className)}>

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 think this alternative would add a class name of undefined when there is no className, right?

Copy link
Contributor

@nicko-winner nicko-winner May 19, 2020

Choose a reason for hiding this comment

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

only if it was written like this: classNames={`hxChoice ${className}`} but className() does not include undefined values.

from the docs: https://github.com/JedWatson/classnames#readme

// other falsy values are just ignored
classNames(null, false, 'bar', undefined, 0, 1, { baz: null }, ''); // => 'bar 1'

<input
checked={wcBool(checked)}
disabled={disabled}
invalid={invalid?.toString()}
name={name}
onChange={onChange}
type="radio"
/>
<hx-tile class={classNames({ hxSubdued: subdued, [SIZES[size]]: true })} {...rest}>
<hx-icon type="checkmark"></hx-icon>
{icon && (
<div className="hx-tile-icon">
<hx-icon type={icon}></hx-icon>
</div>
)}
<header>{title}</header>
{children}
</hx-tile>
</label>
);
};

ChoiceTile.propTypes = {
checked: PropTypes.bool.isRequired,
children: PropTypes.node,
className: PropTypes.string,
disabled: PropTypes.bool,
icon: PropTypes.string,
invalid: PropTypes.bool,
name: PropTypes.string.isRequired,
onChange: PropTypes.func,
size: PropTypes.oneOf(SIZES),
subdued: PropTypes.bool,
title: PropTypes.string.isRequired,
};

ChoiceTile.defaultProps = {
checked: false,
};

export default ChoiceTile;
65 changes: 65 additions & 0 deletions src/Choice Tile/stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React from 'react';
import { action } from '@storybook/addon-actions';
import { optionsKnob as options } from '@storybook/addon-knobs';
import { boolean, select, text } from '@storybook/addon-knobs/react';
import { storiesOf } from '@storybook/react';

import ChoiceTile from './index';
import { getShortText } from '../storyUtils';

const SIZES = {
small: 'small',
medium: 'medium',
large: 'large',
};

storiesOf('Choice Tile', module).add('All Knobs', () => {
let description = text('description', '');
let title = text('title', '');
let checked = boolean('checked', false);
let disabled = boolean('disabled', false);
let invalid = boolean('invalid', false);
let subdued = boolean('subdued', false);
let size = select('size', SIZES, 'medium');
let icon = options(
'icon',
{
account: 'account',
bell: 'bell',
key: 'key',
},
'key',
{ display: 'inline-radio' }
);

const defaultDescription = getShortText();
const defaultTitle = 'Title Here';

return (
<React.Fragment>
<ChoiceTile
{...(checked && { checked })}
{...(disabled && { disabled })}
{...(invalid && { invalid })}
{...(subdued && { subdued })}
{...(size && { size })}
icon={icon}
name="choiceTileDemo"
onChange={action('onChange')}
style={{ width: 200 }}
title={title || defaultTitle}
>
{<p>{description || defaultDescription}</p>}
</ChoiceTile>

<ChoiceTile
icon="bell"
name="choiceTileDemo"
style={{ marginLeft: 25, width: 200 }}
title="Other Choice"
>
{<p>{defaultDescription}</p>}
</ChoiceTile>
</React.Fragment>
);
});
2 changes: 2 additions & 0 deletions src/storyUtils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const getShortText = () => `lorem ipsum dolor sir amet`;

export const getLongText = () => `
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Gravida rutrum quisque non tellus. Sagittis vitae et leo duis
Expand Down