Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trial Bar: Add component #2025

Merged
merged 20 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
79 changes: 79 additions & 0 deletions components/component-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -9019,6 +9019,17 @@
"required": false,
"description": "A unique ID is needed in order to support keyboard navigation, ARIA support, and connect the dropdown to the triggering button."
},
"inverse": {
"type": {
"name": "bool"
},
"required": false,
"description": "Adds inverse class to the dropdown",
"defaultValue": {
"value": "false",
"computed": false
}
},
"isOpen": {
"type": {
"name": "bool"
Expand Down Expand Up @@ -15656,6 +15667,74 @@
"SLDS-component-path": "/components/trees",
"dependencies": []
},
"trial-bar": {
"description": "Trial bar components are used to provide an interactive and educational prospect experience for setup.",
"methods": [],
"props": {
"children": {
"type": {
"name": "node"
},
"required": false,
"description": "Provide children of the types `<TrialBarButton />` or `<TrialBarDropdown />` to define the structure of the trial bar.\n```\n<TrialBar>\n <TrialBarButton />\n <TrialBarDropdown />\n</TrialBar>\n```"
},
"className": {
"type": {
"name": "union",
"value": [
{
"name": "array"
},
{
"name": "object"
},
{
"name": "string"
}
]
},
"required": false,
"description": "CSS classes to be added to the component. Uses `classNames` [API](https://github.com/JedWatson/classnames)."
},
"labels": {
"type": {
"name": "shape",
"value": {
"timeLeft": {
"name": "string",
"description": "Amount of time left in trial, e.g. `30`",
"required": false
},
"timeLeftUnit": {
"name": "string",
"description": "Unit of the amount of time left, e.g. `days`",
"required": false
}
}
},
"required": false,
"description": "Renders the labels in the trial bar."
},
"onRenderActions": {
"type": {
"name": "func"
},
"required": false,
"description": "Renders the actions section of the trial bar."
},
"style": {
"type": {
"name": "object"
},
"required": false,
"description": "Customs styles to be applied to the component."
}
},
"route": "trial-bars",
"display-name": "Trial Bars",
"SLDS-component-path": "/components/trial-bar",
"dependencies": []
},
"vertical-navigation": {
"description": "Vertical Navigation represents a list of links that either take the user to another page or parts of the page the user is in.",
"methods": [
Expand Down
8 changes: 8 additions & 0 deletions components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ export UtilityIcon from './utilities/utility-icon';
export SLDSTree from './tree';
export Tree from './tree';

export SLDSTrialBar from './trial-bar';
export TrialBar from './trial-bar';

export SLDSTrialBarDropdown from './trial-bar/dropdown';
export TrialBarDropdown from './trial-bar/dropdown';
export SLDSTrialBarButton from './trial-bar/button';
export TrialBarButton from './trial-bar/button';

export SLDSVerticalNavigation from './vertical-navigation';
export VerticalNavigation from './vertical-navigation';

Expand Down
13 changes: 13 additions & 0 deletions components/menu-dropdown/__tests__/dropdown.browser-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ describe('SLDSMenuDropdown', function() {
});
});

describe('Inverse', () => {
beforeEach(mountComponent(<DemoComponent inverse />));

afterEach(unmountComponent);

it('has correct CSS class for inverse', function() {
const nodes = getNodes({ wrapper: this.wrapper });
nodes.button.simulate('click', {});
const openNodes = getNodes({ wrapper: this.wrapper });
expect(openNodes.menu.hasClass('slds-dropdown_inverse')).to.equal(true);
});
});

describe('Custom Content Present', () => {
beforeEach(
mountComponent(
Expand Down
10 changes: 9 additions & 1 deletion components/menu-dropdown/menu-dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ const propTypes = {
* A unique ID is needed in order to support keyboard navigation, ARIA support, and connect the dropdown to the triggering button.
*/
id: PropTypes.string,
/**
* Adds inverse class to the dropdown
*/
inverse: PropTypes.bool,
/**
* Forces the dropdown to be open or closed. See controlled/uncontrolled callback/prop pattern for more on suggested use view [Concepts and Best Practices](https://github.com/salesforce-ux/design-system-react/blob/master/CONTRIBUTING.md#concepts-and-best-practices)
*/
Expand Down Expand Up @@ -402,6 +406,7 @@ const defaultProps = {
menuPosition: 'absolute',
openOn: 'click',
width: 'medium',
inverse: false,
};

/**
Expand Down Expand Up @@ -921,7 +926,10 @@ class MenuDropdown extends React.Component {
`slds-dropdown_${this.props.width}`,
'ignore-react-onclickoutside',
this.props.className,
positionClassName
positionClassName,
{
'slds-dropdown_inverse': this.props.inverse,
}
)}
context={this.context}
hasNubbin={hasNubbin}
Expand Down
1 change: 1 addition & 0 deletions components/site-stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const documentationSiteLiveExamples = {
toast: require('@salesforce/design-system-react/components/toast/__docs__/site-stories.js'),
tooltip: require('@salesforce/design-system-react/components/tooltip/__docs__/site-stories.js'),
tree: require('@salesforce/design-system-react/components/tree/__docs__/site-stories.js'),
'trial-bar': require('@salesforce/design-system-react/components/trial-bar/__docs__/site-stories.js'),
'vertical-navigation': require('@salesforce/design-system-react/components/vertical-navigation/__docs__/site-stories.js'),
'visual-picker': require('@salesforce/design-system-react/components/visual-picker/__docs__/site-stories.js'),
};
Expand Down
1 change: 1 addition & 0 deletions components/story-based-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export Textarea from '../components/textarea/__docs__/storybook-stories';
export Toast from '../components/toast/__docs__/storybook-stories';
export Tooltip from '../components/tooltip/__docs__/storybook-stories';
export Tree from '../components/tree/__docs__/storybook-stories';
export TrialBar from '../components/trial-bar/__docs__/storybook-stories';
export VerticalNavigation from '../components/vertical-navigation/__docs__/storybook-stories';
export VisualPicker from '../components/visual-picker/__docs__/storybook-stories';

Expand Down
1 change: 1 addition & 0 deletions components/storybook-stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ export TimePicker from '../components/time-picker/__docs__/storybook-stories';
export Toast from '../components/toast/__docs__/storybook-stories';
export Tooltip from '../components/tooltip/__docs__/storybook-stories';
export Tree from '../components/tree/__docs__/storybook-stories';
export TrialBar from '../components/trial-bar/__docs__/storybook-stories';
export VerticalNavigation from '../components/vertical-navigation/__docs__/storybook-stories';
export VisualPicker from '../components/visual-picker/__docs__/storybook-stories';
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`DOM snapshots SLDSTrialBar Default 1`] = `
<div
className="slds-p-around_medium"
>
<div>
<div
className="slds-trial-header slds-grid"
>
<div
className="slds-grid"
>
<button
className="slds-button slds-button_inverse slds-m-right_small"
disabled={false}
onClick={[Function]}
style={
Object {
"border": 0,
"padding": 0,
}
}
type="button"
>
Take the salesforce tour
</button>
<div
className="slds-dropdown-trigger slds-dropdown-trigger_click slds-grid"
id="dropdown"
onClick={[Function]}
onFocus={null}
onKeyDown={[Function]}
onMouseEnter={null}
onMouseLeave={null}
>
<button
aria-expanded={false}
aria-haspopup={true}
className="slds-button slds-button_inverse ignore-click-dropdown"
disabled={false}
onClick={[Function]}
style={
Object {
"border": 0,
"height": "100%",
"padding": 0,
}
}
tabIndex="0"
type="button"
>
<svg
aria-hidden="true"
className="slds-button__icon slds-button__icon_left"
>
<use
xlinkHref="/assets/icons/utility-sprite/svg/symbols.svg#right"
/>
</svg>
Choose your tour
</button>
</div>
</div>
<div
className="slds-grid slds-grid_vertical-align-center slds-col_bump-left"
>
<span
className="slds-box slds-box_xx-small slds-theme_default"
>
30
</span>
<span
className="slds-m-horizontal_x-small"
>
days
left in trial
</span>
<button
className="slds-button slds-button_success"
disabled={false}
onClick={[Function]}
type="button"
>
Subscribe Now
</button>
</div>
</div>
</div>
</div>
`;
10 changes: 10 additions & 0 deletions components/trial-bar/__docs__/site-stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This object is imported into the documentation site. An example for the documentation site should be part of the pull request for the component. The object key is the kabob case of the "URL folder". In the case of `http://localhost:8080/components/app-launcher/`, `app-launcher` is the `key`. The folder name is created by `components.component` value in `package.json`. The following uses webpack's raw-loader plugin to get "text files" that will be eval()'d by CodeMirror within the documentation site on page load.

/* eslint-env node */
/* eslint-disable global-require */

const siteStories = [
require('raw-loader!@salesforce/design-system-react/components/trial-bar/__examples__/default.jsx'),
];

module.exports = siteStories;
10 changes: 10 additions & 0 deletions components/trial-bar/__docs__/storybook-stories.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { TRIAL_BAR } from '../../../utilities/constants';
import Default from '../__examples__/default';

storiesOf(TRIAL_BAR, module)
.addDecorator((getStory) => (
<div className="slds-p-around_medium">{getStory()}</div>
))
.add('Default', () => <Default />);
46 changes: 46 additions & 0 deletions components/trial-bar/__examples__/default.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import TrialBar from '~/components/trial-bar';
import TrialBarDropdown from '~/components/trial-bar/dropdown';
import TrialBarButton from '~/components/trial-bar/button';
import IconSettings from '~/components/icon-settings';
import Button from '~/components/button';

class Example extends React.Component {
render() {
return (
<IconSettings iconPath="/assets/icons">
<div>
<TrialBar
labels={{ timeLeft: '30', timeLeftUnit: 'days' }}
onRenderActions={() => (
<Button variant="success" label="Subscribe Now" />
)}
>
<TrialBarButton label="Take the salesforce tour" />
<TrialBarDropdown
assistiveText={{ icon: 'Dropdown' }}
id="dropdown"
label="Choose your tour"
options={[
{ label: 'Conquer Your Cases', value: 'item1' },
{ label: 'Automate For Speed', value: 'item2' },
{ label: 'Share Your Knowledge', value: 'item3' },
{ label: 'Finish it up in a Flash', value: 'item4' },
{ type: 'divider' },
{
label: 'Import Contacts and Accounts',
value: 'item5',
leftIcon: { name: 'upload', category: 'utility' },
},
]}
value={['item1']}
/>
</TrialBar>
</div>
</IconSettings>
);
}
}
Example.displayName = 'TrialBarDefault';

export default Example; // export is replaced with `ReactDOM.render(<Example />, mountNode);` at runtime
24 changes: 24 additions & 0 deletions components/trial-bar/button.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import Button from '~/components/button';
import { TRIAL_BAR_BUTTON } from '../../utilities/constants';

// This component accepts the same props as Button.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a doc site matter, so it's not very obvious, but this comment should follow the way that component descriptions should to be written to be picked up by react-docgen. I think that requires the comment it to in multi-line quote comment on the line directly before the class/function declaration. A markdown URL to the Button page would be good https://react.lightningdesignsystem.com/components/buttons/ . I think there are other examples in the library. The easiest way to check is to run npm build:docs and make sure this component shows up.

@davidlygagnon I'd recommend running the doc site consuming this branch locally to make sure all the comments and props show up correctly--or maintainers can fix this up, since the doc site isn't public. Either way is fine. As you know, the whole library/doc site can be finicky. Kevin and I spent some time with Setup Assistant yesterday.

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 have added multi-line comments right before the components declaration but haven't removed the propTypes. It is as done in BuilderHeader component that I was using as a reference. Let me know if this needs further updation.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm referring to doc comments only. Please see https://github.com/salesforce/design-system-react/blob/master/components/builder-header/nav-dropdown.jsx#L16

which shows up on the doc site here:
Screen Shot 2019-06-13 at 1 57 59 PM

Please add a link to the doc site Button there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool - I'll double check by building the doc site locally.

// eslint-disable-next-line react/forbid-foreign-prop-types
const { propTypes } = Button;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we really need this and whether it will break people that are using the babel-plugin-transform-react-remove-prop-types plugin to remove props. Would it be sufficient to just have a link pointing to the Dropdown component?

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 used BuilderHeader for reference, if that's working for the consumers I don't think this is much different. I will update it if need be.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok - let's leave as is then.


/**
* A [Button](/components/buttons/) within the Trial Bar.
*/
const TrialBarButton = (props) => (
<Button
{...props}
inverse
style={{ border: 0, padding: 0 }}
className="slds-m-right_small"
/>
);

TrialBarButton.propTypes = propTypes;
TrialBarButton.displayName = TRIAL_BAR_BUTTON;

export default TrialBarButton;
7 changes: 7 additions & 0 deletions components/trial-bar/docs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"component": "trial-bar",
"status": "prototype",
"display-name": "Trial Bars",
"SLDS-component-path": "/components/trial-bar",
"url-slug": "trial-bars"
}
Loading