Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4873 from kobotoolbox/task-542-transcription-esti…
…mation [TASK-542] Display automated transcription estimate
- Loading branch information
Showing
30 changed files
with
398 additions
and
214 deletions.
There are no files selected for viewing
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
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,20 @@ | ||
import type {ReactElement} from 'react'; | ||
import React from 'react'; | ||
import styles from './centeredMessage.module.scss'; | ||
|
||
interface CenteredMessageProps { | ||
message: ReactElement<any, any> | string; | ||
} | ||
|
||
/** | ||
* A centered message component. | ||
*/ | ||
export default function CenteredMessage(props: CenteredMessageProps) { | ||
return ( | ||
<figure className={styles.centeredMessage}> | ||
<div className={styles.centeredMessageInner}> | ||
{props.message} | ||
</div> | ||
</figure> | ||
); | ||
} |
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,16 @@ | ||
.centeredMessage { | ||
display: table; | ||
vertical-align: middle; | ||
height: 100%; | ||
width: 100%; | ||
font-size: 18px; | ||
margin: 0; | ||
} | ||
|
||
.centeredMessageInner { | ||
display: table-cell; | ||
vertical-align: middle; | ||
text-align: center; | ||
padding-left: 20px; | ||
padding-right: 20px; | ||
} |
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,99 @@ | ||
@use '~kobo-common/src/styles/colors'; | ||
@use 'scss/_variables'; | ||
|
||
// Loading messages | ||
.loading { | ||
display: table; | ||
vertical-align: middle; | ||
height: 100%; | ||
width: 100%; | ||
font-size: 18px; | ||
opacity: 0.8; | ||
} | ||
|
||
// Adjust spinning icon position for the regular spinner | ||
.loadingTypeRegular { | ||
i:first-child { | ||
vertical-align: -7px; | ||
display: inline-block; | ||
} | ||
} | ||
|
||
// Moves message a bit off center to make it appear centered (ellipsis causes | ||
// this optical illusion) | ||
.loadingHasDefaultMessage { | ||
.loadingMessage { | ||
padding-left: 5px; | ||
} | ||
} | ||
|
||
.loadingMessage { | ||
margin-top: 10px; | ||
display: block; | ||
} | ||
|
||
.loadingInner { | ||
display: table-cell; | ||
vertical-align: middle; | ||
text-align: center; | ||
padding-left: 20px; | ||
padding-right: 20px; | ||
overflow: hidden; // avoids spinner icon overflowing scrollable areas | ||
|
||
code { | ||
margin: 20px; | ||
padding: 15px; | ||
font-size: 13px; | ||
display: block; | ||
background: colors.$kobo-white; | ||
width: 80%; | ||
max-height: 300px; | ||
overflow: auto; | ||
word-wrap: break-word; | ||
text-align: left; | ||
} | ||
} | ||
|
||
@keyframes rotate { | ||
from {transform: rotateZ(360deg);} | ||
to {transform: rotateZ(0deg);} | ||
} | ||
|
||
$spinner-size: 64px; | ||
$spinner-line-size: 10px; | ||
$spinner-mask-size: $spinner-size * 0.5 - $spinner-line-size; | ||
|
||
.bigSpinner { | ||
display: block; | ||
margin: 0 auto; | ||
position: relative; | ||
height: $spinner-size; | ||
width: $spinner-size; | ||
border-radius: 50%; | ||
background: conic-gradient(#{colors.$kobo-blue}, transparent); | ||
animation: rotate 1s linear infinite; | ||
mask-image: radial-gradient(circle, transparent $spinner-mask-size, black 33%); | ||
} | ||
|
||
.bigSpinner::before, | ||
.bigSpinner::after { | ||
content: ''; | ||
position: absolute; | ||
border-radius: 50%; | ||
} | ||
|
||
.bigSpinner::before { | ||
width: $spinner-size - (2 * $spinner-line-size); | ||
height: $spinner-size - (2 * $spinner-line-size); | ||
top: $spinner-line-size; | ||
left: $spinner-line-size; | ||
background-color: colors.$kobo-white; | ||
} | ||
|
||
.bigSpinner::after { | ||
height: $spinner-line-size; | ||
width: $spinner-line-size; | ||
background-color: colors.$kobo-blue; | ||
top: 0; | ||
left: ($spinner-size - $spinner-line-size) * 0.5; | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import type {ComponentStory, ComponentMeta} from '@storybook/react'; | ||
import LoadingSpinner from './loadingSpinner'; | ||
import type {LoadingSpinnerType} from './loadingSpinner'; | ||
|
||
const spinnerTypes: LoadingSpinnerType[] = ['regular', 'big']; | ||
|
||
export default { | ||
title: 'common/LoadingSpinner', | ||
component: LoadingSpinner, | ||
argTypes: { | ||
type: { | ||
description: 'Type of LoadingSpinner', | ||
options: spinnerTypes, | ||
control: 'radio', | ||
}, | ||
message: { | ||
options: [ | ||
undefined, | ||
false, | ||
'Please wait things are coming…', | ||
'Please wait until this process finishes, as there are a lot of things going on in the background. But since you started reading this, most probably the whole thing have already finished…', | ||
], | ||
description: | ||
'Displayed underneath the animating spinner. If custom message is not provided, default message will be displayed. If `false` is passed, message will not be displayed.', | ||
control: 'select', | ||
}, | ||
}, | ||
} as ComponentMeta<typeof LoadingSpinner>; | ||
|
||
const Template: ComponentStory<typeof LoadingSpinner> = (args) => ( | ||
<LoadingSpinner {...args} /> | ||
); | ||
|
||
export const Regular = Template.bind({}); | ||
Regular.args = { | ||
type: 'regular', | ||
message: 'To infinity and beyond…', | ||
}; | ||
|
||
export const Big = Template.bind({}); | ||
Big.args = { | ||
type: 'big', | ||
message: 'Working on it…', | ||
}; |
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 |
---|---|---|
@@ -1,36 +1,48 @@ | ||
import React from 'react'; | ||
import bem from 'js/bem'; | ||
import './loadingSpinner.scss'; | ||
import cx from 'classnames'; | ||
import styles from './loadingSpinner.module.scss'; | ||
import Icon from 'js/components/common/icon'; | ||
|
||
export type LoadingSpinnerType = 'regular' | 'big'; | ||
|
||
interface LoadingSpinnerProps { | ||
message?: string; | ||
/** Changes the looks of the spinner animation. */ | ||
type?: LoadingSpinnerType; | ||
/** | ||
* Most of the times we want a message, either custom or default one, but | ||
* sometimes we want just the spinner. We need a boolean to hide it, because | ||
* component has a fallback message. | ||
* There is a default message if nothing is provided. If you want to hide | ||
* the message completely, pass `false`. | ||
*/ | ||
hideMessage?: boolean; | ||
hideSpinner?: boolean; | ||
message?: string | boolean; | ||
'data-cy'?: string; | ||
} | ||
|
||
export default class LoadingSpinner extends React.Component< | ||
LoadingSpinnerProps, | ||
{} | ||
> { | ||
render() { | ||
const message = this.props.message || t('loading…'); | ||
/** | ||
* Displays a spinner animation above a customizable yet optional message. | ||
*/ | ||
export default function LoadingSpinner(props: LoadingSpinnerProps) { | ||
const spinnerType: LoadingSpinnerType = props.type || 'regular'; | ||
const message = props.message || t('loading…'); | ||
|
||
return ( | ||
<div | ||
className={cx({ | ||
[styles.loading]: true, | ||
[styles.loadingTypeRegular]: spinnerType === 'regular', | ||
[styles.loadingHasDefaultMessage]: props.message === undefined, | ||
})} | ||
data-cy={props['data-cy']} | ||
> | ||
<div className={styles.loadingInner}> | ||
{spinnerType === 'regular' && ( | ||
<Icon name='spinner' size='xl' classNames={['k-spin']} /> | ||
)} | ||
|
||
{spinnerType === 'big' && <span className={styles.bigSpinner} />} | ||
|
||
return ( | ||
<bem.Loading data-cy={this.props['data-cy']}> | ||
<bem.Loading__inner> | ||
{!this.props.hideSpinner && ( | ||
<Icon name='spinner' size='xl' classNames={['k-spin']} /> | ||
)} | ||
{!this.props.hideMessage && message} | ||
</bem.Loading__inner> | ||
</bem.Loading> | ||
); | ||
} | ||
{props.message !== false && ( | ||
<span className={styles.loadingMessage}>{message}</span> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} |
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
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.