Skip to content

Commit

Permalink
Merge pull request #212 from dhis2/fix/transfer-selected-render-option
Browse files Browse the repository at this point in the history
feat(transfer): add prop selected to renderOption (TECH-393)
  • Loading branch information
martinkrulltott authored Jul 10, 2020
2 parents 4af0479 + c81317c commit b256833
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/widgets/src/Transfer/Transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export const Transfer = ({
toggleHighlightedSourceOption
),
highlighted,
selected: false,
})}
</Fragment>
)
Expand Down Expand Up @@ -323,6 +324,7 @@ export const Transfer = ({
toggleHighlightedPickedOption
),
highlighted,
selected: true,
})}
</Fragment>
)
Expand Down
18 changes: 13 additions & 5 deletions packages/widgets/src/Transfer/Transfer.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,13 @@ export const FilterPlaceholder = () => (
</StatefulWrapper>
)

const renderOption = ({ label, value, onClick, highlighted }) => (
const renderOption = ({ label, value, onClick, highlighted, selected }) => (
<p
onClick={event => onClick({ label, value }, event)}
style={{ background: highlighted ? 'green' : 'blue' }}
style={{
background: highlighted ? 'green' : 'blue',
color: selected ? 'orange' : 'white',
}}
>
Custom: {label} (label), {value} (value)
</p>
Expand All @@ -203,16 +206,21 @@ export const CustomListOptions = () => (
<>
<strong>Custom option code:</strong>
<code>
<pre>{`const renderOption = ({ label, value, onClick, highlighted }) => (
<pre>{`const renderOption = ({ label, value, onClick, highlighted, selected }) => (
<p
onClick={event => onClick({ label, value }, event)}
style={{ background: highlighted ? 'green' : 'blue' }}
style={{
background: highlighted ? 'green' : 'blue',
color: selected ? 'orange' : 'white',
}}
>
Custom: {label} (label), {value} (value)
</p>
)`}</pre>
</code>
<StatefulWrapper>
<StatefulWrapper
initialState={options.slice(0, 2).map(({ value }) => value)}
>
<Transfer
onChange={() =>
console.log('Will be overriden by StatefulWrapper')
Expand Down

0 comments on commit b256833

Please sign in to comment.