-
Notifications
You must be signed in to change notification settings - Fork 377
WIP feat(DatePicker): Add DatePicker component #226
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Custom loader for node-sass to allow paths in the sass files to | ||
| * be prefixed with '@' for a custom mapping (contained in this file) | ||
| * of to be prefixed with '~' for a mapping to a node_modules package. | ||
| */ | ||
| const path = require('path'); | ||
| const findParentDir = require('find-parent-dir'); | ||
| const nodeSassTildeImporter = require('node-sass-tilde-importer'); | ||
|
|
||
| const mappings = { | ||
| '@patternfly': 'node_modules/patternfly/dist/sass', | ||
| '@bootstrap': 'node_modules/patternfly/node_modules/bootstrap-sass/assets/stylesheets', | ||
| '@fontAwesome': 'node_modules/patternfly/node_modules/font-awesome-sass/assets/stylesheets' | ||
| }; | ||
|
|
||
| module.exports = function importer(url, prev, done) { | ||
| const url__ = url; | ||
|
|
||
| if (url[0] === '@') { | ||
| const packageRoot = findParentDir.sync(prev, 'node_modules'); | ||
| if (!packageRoot) return null; | ||
|
|
||
| const mapTarget = url.substr(0, url.indexOf('/')); | ||
| if (mappings[mapTarget]) { | ||
| url = path.resolve(packageRoot, mappings[mapTarget], url.substr(1)); | ||
| } | ||
| } else if (url[0] === '~') { | ||
| return nodeSassTildeImporter(url, prev, done); | ||
| } | ||
|
|
||
| // console.log(`url "${url__}" ==> "${url}"`); | ||
| return { file: url }; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,22 +2,23 @@ | |
| Third Party / Dependency imports here | ||
| */ | ||
| $font-path: '~patternfly/dist/fonts/'; | ||
| $img-path: '~patternfly/dist/img/'; | ||
| $img-path: '~patternfly/dist/img/'; | ||
| $icon-font-path: '~patternfly/dist/fonts/'; | ||
|
|
||
|
|
||
| // Bootstrap Core variables and mixins | ||
| @import "bootstrap/variables"; | ||
| @import "bootstrap/mixins"; | ||
| @import "@bootstrap/variables"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Creating a special syntax will make it difficult to import this file for consumers.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't expect consumers would import this file, rather they would import the patternfly-react partials. But if there is a better way to avoid the special syntax, that would be better.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh you right, it's a bit confusing since they use they same name
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really the reason I put the "@" there was to indicate that the import is coming from somewhere non-standard. In this case, the bootstrap and fontawesome imports all come from the patternfly package. That was achieved by including those source sass directories directly on the command line. I though about changing the import to something that webpack would understand natively like:
but that seemed worse. |
||
| @import "@bootstrap/mixins"; | ||
|
|
||
| // Patternfly Core variables and mixins | ||
| @import 'patternfly/variables'; | ||
| @import 'patternfly/fonts'; | ||
| @import 'patternfly/bootstrap-mixin-overrides'; | ||
| @import 'patternfly/mixins'; | ||
| @import '@patternfly/variables'; | ||
| @import '@patternfly/fonts'; | ||
| @import '@patternfly/bootstrap-mixin-overrides'; | ||
| @import '@patternfly/mixins'; | ||
|
|
||
| /** | ||
| Patternfly React Specific Extensions | ||
| */ | ||
|
|
||
| @import 'patternfly-react/patternfly-react'; | ||
|
|
||
| // React Wigets DateTimePicker imports | ||
| @import 'patternfly-react/react-widgets'; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| $font-path: '~react-widgets/lib/fonts'; | ||
| $img-path: '~react-widgets/lib/img'; | ||
|
|
||
| @import '~react-widgets/lib/scss/react-widgets'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import React from 'react'; | ||
| import { | ||
| compose, | ||
| setPropTypes, | ||
| withProps, | ||
| defaultProps, | ||
| renameProp | ||
| } from 'recompose'; | ||
| import { DateTimePicker } from 'react-widgets'; | ||
|
|
||
| // Setup localizer for the DatePicker via moment - default to English (en) | ||
| import momentLocalizer from 'react-widgets-moment'; | ||
| momentLocalizer(); | ||
|
|
||
| const enhance = compose( | ||
| // RwDateTimePicker uses 'culture' instead of the more common 'locale' or | ||
| // the 'language' used by bootstrap-datepicker | ||
| renameProp('locale', 'culture'), | ||
|
|
||
| setPropTypes({ | ||
| ...DateTimePicker.propTypes | ||
| }), | ||
| defaultProps({ | ||
| format: 'MM/DD/YYYY' // moment.js format patterns | ||
| }), | ||
| withProps({ | ||
| date: true, | ||
| time: false | ||
| }) | ||
| ); | ||
|
|
||
| /* | ||
| Reference Markup on Bootstrap Datepicker... | ||
| autoclose: true, | ||
| todayBtn: "linked", | ||
| todayHighlight: true | ||
|
|
||
| How to... | ||
| remove the inline open popup button? | ||
| change the popup button icon? | ||
|
|
||
| */ | ||
|
|
||
| const DatePicker = enhance(({ className, ...props }) => ( | ||
| <DateTimePicker className={className} {...props} /> | ||
| )); | ||
|
|
||
| export default DatePicker; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import React from 'react'; | ||
| import { storiesOf } from '@storybook/react'; | ||
| import { action } from '@storybook/addon-actions'; | ||
| import { inlineTemplate } from '../../../storybook/decorators/storyTemplates'; | ||
| import { DOCUMENTATION_URL as DOC_URL } from '../../../storybook/constants'; | ||
| import { DatePicker } from './index'; | ||
|
|
||
| // Setup the default localization to English (en) | ||
| import Moment from 'moment'; | ||
| Moment.locale('en'); | ||
|
|
||
| const stories = storiesOf('DatePicker', module); | ||
|
|
||
| stories.addWithInfo('DatePicker', '', () => { | ||
| let story = ( | ||
| <div> | ||
| <DatePicker onChange={action('onChange')} /> | ||
| </div> | ||
| ); | ||
| return inlineTemplate({ | ||
| title: 'DatePicker', | ||
| documentationLink: `${DOC_URL.PATTERNFLY_ORG_WIDGETS}#bootstrap-datepicker`, | ||
| description: '', | ||
| story | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default as DatePicker } from './DatePicker'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using node-sass-package-importer
I used a different feature from node-sass-magic-importer and the experience was great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tilde import part works the same way, but the other features are interesting.