This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: restore slot handling based on element contents (#548)
* feat: restore slot handling based on element contents * style: remove disabled code * feat: support jsdoc meta data for slots * feat: make elements with slots collapsible * fix: provide root drop zone on 100% of element list height * fix: add slot description * fix: remove duplicate stylings
- Loading branch information
Showing
25 changed files
with
1,007 additions
and
495 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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,50 @@ | ||
import DemoContainer from '../demo-container'; | ||
import * as React from 'react'; | ||
import { ElementSlot, ElementSlotState } from '.'; | ||
|
||
const FloatingButtonDemo: React.StatelessComponent<void> = (): JSX.Element => ( | ||
<DemoContainer title="Element Slot"> | ||
<> | ||
Default | ||
<ElementSlot | ||
description="Slot" | ||
id="" | ||
open={false} | ||
state={ElementSlotState.Default} | ||
title="Slot" | ||
/> | ||
</> | ||
<> | ||
Open | ||
<ElementSlot | ||
description="Slot" | ||
id="" | ||
open={true} | ||
state={ElementSlotState.Default} | ||
title="Open Slot" | ||
/> | ||
</> | ||
<> | ||
Disabled | ||
<ElementSlot | ||
description="Slot" | ||
id="" | ||
open={true} | ||
state={ElementSlotState.Disabled} | ||
title="Disabled Slot" | ||
/> | ||
</> | ||
<> | ||
Highlighted | ||
<ElementSlot | ||
description="Slot" | ||
id="" | ||
open={true} | ||
state={ElementSlotState.Highlighted} | ||
title="Disabled Slot" | ||
/> | ||
</> | ||
</DemoContainer> | ||
); | ||
|
||
export default FloatingButtonDemo; |
This file contains 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,130 @@ | ||
import { Color } from '../colors'; | ||
import { ElementAnchors } from '../element'; | ||
import { Icon, IconName, IconSize } from '../icons'; | ||
import * as React from 'react'; | ||
import { getSpace, SpaceSize } from '../space'; | ||
import styled from 'styled-components'; | ||
import { tag } from '../tag'; | ||
|
||
export enum ElementSlotState { | ||
Default = 'default', | ||
Disabled = 'disabled', | ||
Highlighted = 'highlighted' | ||
} | ||
|
||
export interface ElementSlotProps { | ||
children?: React.ReactNode; | ||
description: string; | ||
id: string; | ||
open: boolean; | ||
state: ElementSlotState; | ||
title: string; | ||
} | ||
|
||
interface StyledElementSlotLabelProps { | ||
state: ElementSlotState; | ||
} | ||
|
||
interface StyledIconProps { | ||
open: boolean; | ||
} | ||
|
||
const StyledElementSlot = styled.div` | ||
position: relative; | ||
z-index: 1; | ||
`; | ||
|
||
const div = tag('div').omit(['active', 'highlight']); | ||
|
||
const LABEL_COLOR = (props: StyledElementSlotLabelProps): string => { | ||
switch (props.state) { | ||
case ElementSlotState.Disabled: | ||
return Color.Grey60; | ||
case ElementSlotState.Highlighted: | ||
case ElementSlotState.Default: | ||
default: | ||
return 'inherit'; | ||
} | ||
}; | ||
|
||
const LABEL_BACKGROUND = (props: StyledElementSlotLabelProps): string => { | ||
switch (props.state) { | ||
case ElementSlotState.Highlighted: | ||
return Color.Grey90; | ||
default: | ||
return 'transparent'; | ||
} | ||
}; | ||
|
||
const StyledElementSlotLabel = styled(div)` | ||
position: relative; | ||
display: flex; | ||
align-items: center; | ||
font-size: 15px; | ||
line-height: 21px; | ||
z-index: 1; | ||
color: ${LABEL_COLOR}; | ||
background: ${LABEL_BACKGROUND}; | ||
`; | ||
|
||
const elementDiv = tag('div').omit(['open']); | ||
|
||
const StyledElementChildren = styled(elementDiv)` | ||
flex-basis: 100%; | ||
padding-left: ${getSpace(SpaceSize.L)}px; | ||
`; | ||
|
||
const StyledIcon = styled(Icon)` | ||
position: absolute; | ||
left: ${getSpace(SpaceSize.XS) + getSpace(SpaceSize.XXS)}px; | ||
fill: ${Color.Grey60}; | ||
width: ${getSpace(SpaceSize.S)}px; | ||
height: ${getSpace(SpaceSize.S)}px; | ||
padding: ${getSpace(SpaceSize.XS)}px; | ||
transition: transform 0.2s; | ||
${(props: StyledIconProps) => (props.open ? 'transform: rotate(90deg)' : '')}; | ||
`; | ||
|
||
const StyledElementSlotLabelContent = styled.div` | ||
box-sizing: border-box; | ||
margin-left: ${getSpace(SpaceSize.XXL) - 3}px; | ||
overflow: hidden; | ||
padding: ${getSpace(SpaceSize.XS)}px ${getSpace(SpaceSize.XXS)}px; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
width: 100%; | ||
`; | ||
|
||
const StyledElementSlotLabelDescription = styled.div` | ||
box-sizing: border-box; | ||
padding: 0 ${getSpace(SpaceSize.M)}px 0 ${getSpace(SpaceSize.XS)}px; | ||
font-size: 12px; | ||
justify-self: flex-end; | ||
`; | ||
|
||
export class ElementSlot extends React.Component<ElementSlotProps> { | ||
public render(): JSX.Element | null { | ||
const { props } = this; | ||
|
||
return ( | ||
<StyledElementSlot {...{ [ElementAnchors.content]: props.id }}> | ||
<StyledElementSlotLabel state={props.state}> | ||
<StyledIcon | ||
dataIcon={props.id} | ||
name={IconName.ArrowFillRight} | ||
size={IconSize.XXS} | ||
color={Color.Grey60} | ||
open={props.open} | ||
/> | ||
<StyledElementSlotLabelContent {...{ [ElementAnchors.label]: true }}> | ||
{props.title} | ||
</StyledElementSlotLabelContent> | ||
<StyledElementSlotLabelDescription> | ||
{props.description} | ||
</StyledElementSlotLabelDescription> | ||
</StyledElementSlotLabel> | ||
<StyledElementChildren>{props.open && props.children}</StyledElementChildren> | ||
</StyledElementSlot> | ||
); | ||
} | ||
} |
This file contains 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 @@ | ||
export * from './element-slot'; |
This file contains 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,9 @@ | ||
{ | ||
"name": "element-slot", | ||
"main": "./element-slot", | ||
"description": "Slot in element tree", | ||
"displayName": "Element Slot", | ||
"flag": "alpha", | ||
"version": "1.0.0", | ||
"tags": [] | ||
} |
This file contains 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
Oops, something went wrong.