Skip to content

Commit

Permalink
FIX (label, value): [EXPERIMENTAL] allow dotted path in valueField an… (
Browse files Browse the repository at this point in the history
#18)

* FIX (label, value): allow dotted path in valueField, labelField, searchBy and sortBy  issue #17
  • Loading branch information
sanusart authored Jul 19, 2019
1 parent 88d2513 commit 43eefe0
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 64 deletions.
2 changes: 1 addition & 1 deletion dist/react-dropdown-select.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module.exports = {
pathPrefix: "/react-dropdown-select",
pathPrefix: '/react-dropdown-select',
plugins: [
`gatsby-plugin-emotion`,
{
resolve: `gatsby-source-filesystem`,
options: {
path: `${__dirname}/src/pages`,
name: "markdown-pages",
},
name: 'markdown-pages'
}
},
`gatsby-transformer-remark`,
`gatsby-plugin-catch-links`
Expand All @@ -32,6 +32,6 @@ module.exports = {
path: 'examples',
displayName: 'Examples'
}
],
]
}
};
38 changes: 38 additions & 0 deletions docs/src/examples/AccessDataByPath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import styled from '@emotion/styled';

import Select from '../../../src';
import { options } from '../options';

const AccessDataByPath = ({ title }) => (
<React.Fragment>
<Title>
<h2>{title}</h2>
<a href="https://github.com/sanusart/react-dropdown-select/tree/master/docs/src/examples/AccessDataByPath.js">
Source
</a>
</Title>
<p>"Label" is accessed via <code>company.catchPhrase</code> nested property of the <a href="https://github.com/sanusart/react-dropdown-select/tree/master/docs/src/options.js#L21">options</a> object</p>
<Select
multi
options={options}
values={[]}
valueField="address.city"
labelField="company.catchPhrase"
searchBy="company.catchPhrase"
onChange={(value) =>
console.log(`%c > onChange ${title} `, 'background: #555; color: tomato', value)
}
/>
</React.Fragment>
);

AccessDataByPath.propTypes = {};

const Title = styled.div`
display: flex;
justify-content: space-between;
align-items: baseline;
`;

export default AccessDataByPath;
10 changes: 5 additions & 5 deletions docs/src/pages/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ title: 'API'
| separator | bool | false | Separator line between close all and dropdown handle |
| dropdownHandle | bool | true | Dropdown handle to open/close dropdown |
| dropdownHeight | string | "300px" | Minimum height of a dropdown |
| [direction](https://sanusart.github.io/react-dropdown-select/examples/#Right-to-left) | string | "ltr" | direction of a dropdown "ltr", "rtl" or "auto" |
| searchBy | string | label | Search by object property in values |
| sortBy | string | null | Sort by object property in values |
| labelField | string | "label" | Field in data to use for label |
| valueField | string | "value" | Field in data to use for value |
| [direction](https://sanusart.github.io/react-dropdown-select/examples/#Right-to-left) | string | "ltr" | direction of a dropdown "ltr", "rtl" or "auto" |
| searchBy | string | label | Search by object property (or nested property with dot notation) in values |
| sortBy | string | null | Sort by object property (or nested property with dot notation) in values |
| labelField | string | "label" | Field (or nested property with dot notation) in data to use for label |
| valueField | string | "value" | Field (or nested property with dot notation) in data to use for value |
| color | string | "#0074D9" | Base color to use in component, also can be overwritten via CSS |
| closeOnScroll | bool | false | If true, scrolling the page will close the dropdown |
| closeOnSelect | bool | false | If true, selecting option will close the dropdown |
Expand Down
5 changes: 5 additions & 0 deletions docs/src/pages/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import Rtl from '../examples/Rtl';
import DropdownAutoPosition from '../examples/DropdownAutoPosition';
import NoData from '../examples/NoData';
import ExternalClear from '../examples/ExternalClear';
import AccessDataByPath from '../examples/AccessDataByPath';

const demoOptions = options.map((option) => ({
...option,
Expand Down Expand Up @@ -96,6 +97,10 @@ const Examples = () => (
<ExternalClear options={demoOptions} title={`External clear and add`} />
</Wrapper>

<Wrapper>
<AccessDataByPath title={`Access data by dotted path`} />
</Wrapper>

<br />
<br />
<br />
Expand Down
2 changes: 1 addition & 1 deletion lib/components/Content.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 43eefe0

Please sign in to comment.