Skip to content

load solution with help balloon #52

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

Merged
merged 1 commit into from
Nov 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions web-app/src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import * as React from 'react'
import { Button as AlifdButton } from '@alifd/next'

interface Props {
children: string
style?: React.CSSProperties
children: string | React.ReactNode
disabled?: boolean
type?: 'primary' | 'secondary' | 'normal'
onClick(): void
onClick?: () => void
}

const Button = (props: Props) => (
<AlifdButton onClick={props.onClick} type={props.type}>
<AlifdButton onClick={props.onClick} type={props.type} disabled={props.disabled} style={props.style}>
{props.children}
</AlifdButton>
)
Expand Down
15 changes: 15 additions & 0 deletions web-app/src/components/Icon/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from 'react'
import { Icon as AlifdIcon } from '@alifd/next'

interface Props {
type: string
role?: string
style?: React.CSSProperties
size?: 'xxs' | 'xs' | 'small' | 'medium' | 'large' | 'xl' | 'xxl' | 'xxxl' | 'inherit'
}

const Icon = (props: Props) => {
return <AlifdIcon type={props.type} role={props.role} size={props.size} style={props.style} />
}

export default Icon
55 changes: 55 additions & 0 deletions web-app/src/components/StepHelp/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as React from 'react'
import { Balloon } from '@alifd/next'
import Button from '../Button'
import Icon from '../Icon'

const styles = {
iconButton: {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
width: 30,
height: 30,
},
balloonTitle: {
marginTop: 0,
},
balloonOptions: {
display: 'flex',
justifyContent: 'center',
},
}

interface Props {
onLoadSolution(): void
}

const StepHelp = (props: Props) => {
// TODO: extract or replace load solution
const [loadedSolution, setLoadedSolution] = React.useState()
const onClickHandler = () => {
if (!loadedSolution) {
setLoadedSolution(true)
props.onLoadSolution()
}
}
const promptLeft = (
<Button style={styles.iconButton}>
<Icon type="prompt" role="button" />
</Button>
)
return (
<Balloon trigger={promptLeft} align="l" alignEdge triggerType="click" style={{ width: 300 }}>
<div>
<h4 style={styles.balloonTitle}>Stuck? Need help?</h4>
<div style={styles.balloonOptions}>
<Button type="secondary" onClick={onClickHandler} disabled={loadedSolution}>
Load Solution
</Button>
</div>
</div>
</Balloon>
)
}

export default StepHelp
46 changes: 22 additions & 24 deletions web-app/src/containers/Tutorial/LevelPage/Level/Step/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react'
import * as T from 'typings'
import Button from '../../../../../components/Button'
import Checkbox from '../../../../../components/Checkbox'
import Markdown from '../../../../../components/Markdown'
import StepHelp from '../../../../../components/StepHelp'

interface Props {
order: number
Expand All @@ -20,34 +20,32 @@ const styles = {
content: {
margin: 0,
},
options: {
display: 'flex' as 'flex',
flexDirection: 'row' as 'row',
justifyContent: 'flex-end',
alignItems: 'center' as 'center',
padding: '0.5rem',
},
}

const Step = (props: Props) => {
// TODO: extract or replace load solution
const [loadedSolution, setLoadedSolution] = React.useState()
const onClickHandler = () => {
if (!loadedSolution) {
setLoadedSolution(true)
props.onLoadSolution()
}
}
const showLoadSolution = props.status === 'ACTIVE' && !loadedSolution

const showLoadSolution = props.status === 'ACTIVE'
return (
<div style={styles.card}>
<div>
<Checkbox status={props.status} />
</div>
<div>
<Markdown>{props.content || ''}</Markdown>
</div>
<div>
{showLoadSolution && (
<Button type="normal" onClick={onClickHandler}>
Load Solution
</Button>
)}
<div>
<div style={styles.card}>
<div>
<Checkbox status={props.status} />
</div>
<div>
<Markdown>{props.content || ''}</Markdown>
</div>
</div>
{showLoadSolution && (
<div style={styles.options}>
<StepHelp onLoadSolution={props.onLoadSolution} />
</div>
)}
</div>
)
}
Expand Down
6 changes: 4 additions & 2 deletions web-app/stories/utils/SideBarDecorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import * as React from 'react'

const styles = {
container: {
position: 'relative' as 'relative',
left: '25rem',
position: 'absolute' as 'absolute',
boxSizing: 'border-box' as 'border-box',
borderLeft: '2px solid black',
borderRight: '2px solid black',
width: '100%',
width: '50rem',
height: window.innerHeight,
},
}
Expand Down