-
Notifications
You must be signed in to change notification settings - Fork 64
1709 list item structure #1710
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
Open
tomdye
wants to merge
3
commits into
dojo:master
Choose a base branch
from
tomdye:1709-list-item-structure
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
1709 list item structure #1710
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { create, tsx } from '@dojo/framework/core/vdom'; | ||
import List, { ListItem } from '@dojo/widgets/list'; | ||
import states from './states'; | ||
import icache from '@dojo/framework/core/middleware/icache'; | ||
import Example from '../../Example'; | ||
import { | ||
createResourceTemplate, | ||
createResourceMiddleware | ||
} from '@dojo/framework/core/middleware/resources'; | ||
|
||
const resource = createResourceMiddleware(); | ||
const factory = create({ icache, resource }); | ||
const template = createResourceTemplate<typeof states[0]>('value'); | ||
|
||
export default factory(function NoPadding({ id, middleware: { icache, resource } }) { | ||
return ( | ||
<Example> | ||
<List | ||
resource={resource({ | ||
template: template({ id, data: states }), | ||
transform: { value: 'value', label: 'value' } | ||
})} | ||
onValue={(value) => { | ||
icache.set('value', value); | ||
}} | ||
itemsInView={8} | ||
> | ||
{({ value, label }, props) => ( | ||
<ListItem {...props} padding="none"> | ||
{{ | ||
primary: label | ||
}} | ||
</ListItem> | ||
)} | ||
</List> | ||
<p>{`Clicked On: ${JSON.stringify(icache.getOrSet('value', ''))}`}</p> | ||
</Example> | ||
); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,8 @@ export interface ListItemProperties { | |
onDrop?: (event: DragEvent) => void; | ||
/** Determines if this item is visually collapsed during DnD */ | ||
collapsed?: boolean; | ||
/** Specifies if the list item should be padded, defaults to small */ | ||
padding?: 'none' | 'small' | 'medium'; | ||
} | ||
|
||
export interface ListItemChildren { | ||
|
@@ -116,7 +118,7 @@ export interface ListItemChildren { | |
|
||
const listItemFactory = create({ theme }) | ||
.properties<ListItemProperties>() | ||
.children<ListItemChildren | RenderResult | RenderResult[]>(); | ||
.children<ListItemChildren | RenderResult>(); | ||
|
||
export const ListItem = listItemFactory(function ListItem({ | ||
properties, | ||
|
@@ -140,7 +142,8 @@ export const ListItem = listItemFactory(function ListItem({ | |
movedDown, | ||
collapsed, | ||
theme: themeProp, | ||
variant | ||
variant, | ||
padding = 'medium' | ||
} = properties(); | ||
|
||
const themedCss = theme.classes(listItemCss); | ||
|
@@ -153,10 +156,44 @@ export const ListItem = listItemFactory(function ListItem({ | |
!disabled && !active && onRequestActive(); | ||
} | ||
|
||
const [firstChild, ...otherChildren] = children(); | ||
const { leading = undefined, primary, trailing = undefined } = isRenderResult(firstChild) | ||
? { primary: [firstChild, ...otherChildren] } | ||
: firstChild; | ||
const [firstChild] = children(); | ||
let listContents: RenderResult; | ||
|
||
if (isRenderResult(firstChild)) { | ||
listContents = firstChild; | ||
} else { | ||
const { leading = undefined, primary, trailing = undefined } = firstChild; | ||
listContents = ( | ||
<virtual> | ||
{leading ? <span classes={themedCss.leading}>{leading}</span> : undefined} | ||
<span classes={themedCss.primary}>{primary}</span> | ||
{trailing ? <span classes={themedCss.trailing}>{trailing}</span> : undefined} | ||
{draggable && !trailing && ( | ||
<Icon | ||
type="barsIcon" | ||
classes={{ '@dojo/widgets/icon': { icon: [themedCss.dragIcon] } }} | ||
theme={themeProp} | ||
variant={variant} | ||
/> | ||
)} | ||
</virtual> | ||
); | ||
} | ||
|
||
let paddingClass: string | undefined; | ||
switch (padding) { | ||
case 'small': | ||
paddingClass = themedCss.smallPadding; | ||
break; | ||
case 'medium': | ||
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. Should the options be 'small' and 'large'? 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. could always add a large too, but that's fine by me |
||
paddingClass = themedCss.mediumPadding; | ||
break; | ||
case 'none': | ||
paddingClass = themedCss.noPadding; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
return ( | ||
<div | ||
|
@@ -168,15 +205,15 @@ export const ListItem = listItemFactory(function ListItem({ | |
classes={[ | ||
theme.variant(), | ||
themedCss.root, | ||
themedCss.height, | ||
selected && themedCss.selected, | ||
active && themedCss.active, | ||
disabled && themedCss.disabled, | ||
movedUp && themedCss.movedUp, | ||
movedDown && themedCss.movedDown, | ||
collapsed && themedCss.collapsed, | ||
dragged && themedCss.dragged, | ||
draggable && themedCss.draggable | ||
draggable && themedCss.draggable, | ||
paddingClass | ||
]} | ||
onclick={() => { | ||
requestActive(); | ||
|
@@ -193,17 +230,7 @@ export const ListItem = listItemFactory(function ListItem({ | |
ondrop={onDrop} | ||
styles={{ visibility: dragged ? 'hidden' : undefined }} | ||
> | ||
{leading ? <span classes={themedCss.leading}>{leading}</span> : undefined} | ||
<span classes={themedCss.primary}>{primary}</span> | ||
{trailing ? <span classes={themedCss.trailing}>{trailing}</span> : undefined} | ||
{draggable && !trailing && ( | ||
<Icon | ||
type="barsIcon" | ||
classes={{ '@dojo/widgets/icon': { icon: [themedCss.dragIcon] } }} | ||
theme={themeProp} | ||
variant={variant} | ||
/> | ||
)} | ||
{listContents} | ||
</div> | ||
); | ||
}); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since it is only taking the first child, users of the widget will need to wrap the content in a
<virtual>
element. Should this pass all the children so it could be used like the following?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.
good question