-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2784c24
commit 37efe03
Showing
19 changed files
with
372 additions
and
104 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,15 @@ | ||
.checkbox { | ||
&__input { | ||
display: block; | ||
width: 20px; | ||
height: 20px; | ||
border: 1px solid currentColor; | ||
|
||
&:checked::before { | ||
display: block; | ||
content: 'X'; | ||
width: 10px; | ||
height: 10px; | ||
} | ||
} | ||
} |
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,92 @@ | ||
import React, { ReactNode } from 'react'; | ||
|
||
import { Text } from '../text/text'; | ||
import { FormField, useInputId } from '../form_field/form_field'; | ||
import classnames from 'classnames'; | ||
import './checkbox.scss'; | ||
|
||
interface Props extends FormField<boolean> { | ||
label?: ReactNode; | ||
} | ||
|
||
export function Checkbox({ | ||
name, | ||
value, | ||
ariaLabel, | ||
placeholder, | ||
required, | ||
disabled, | ||
readOnly, | ||
inputId, | ||
label, | ||
touched, | ||
errors, | ||
onChange, | ||
onBlur, | ||
onFocus, | ||
}: Props): JSX.Element { | ||
inputId = useInputId(inputId); | ||
return ( | ||
<div className="checkbox__container"> | ||
<div | ||
className={classnames( | ||
'checkbox', | ||
{ | ||
'checkbox--filled': !!value, | ||
'checkbox--readonly': readOnly, | ||
'checkbox--disabled': disabled, | ||
'checkbox--placeholder': placeholder, | ||
}, | ||
{ disabled } | ||
)} | ||
> | ||
<div className="checkbox__content"> | ||
{label !== undefined && ( | ||
<label | ||
className={classnames('checkbox__label', { | ||
'checkbox__label--disabled': disabled, | ||
})} | ||
htmlFor={inputId} | ||
> | ||
{label} | ||
</label> | ||
)} | ||
<Text> | ||
<input | ||
id={inputId} | ||
name={name} | ||
className={classnames('checkbox__input')} | ||
readOnly={readOnly} | ||
checked={value} | ||
type="checkbox" | ||
onChange={(event) => { | ||
if (readOnly) { | ||
event.preventDefault(); | ||
return; | ||
} | ||
onChange?.(event.target.checked); | ||
}} | ||
onFocus={() => { | ||
onFocus?.(); | ||
}} | ||
onBlur={() => { | ||
onBlur?.(); | ||
}} | ||
placeholder={placeholder} | ||
required={required} | ||
disabled={disabled} | ||
aria-label={ariaLabel} | ||
/> | ||
</Text> | ||
</div> | ||
{touched && errors && ( | ||
<div className="checkbox__errors"> | ||
{errors.map((error) => ( | ||
<Text key={error}>{error}</Text> | ||
))} | ||
</div> | ||
)} | ||
</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
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
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,10 @@ | ||
# frozen_string_literal: true | ||
|
||
render "components/current_user" | ||
|
||
field :feedback, value: -> { @feedback } do | ||
field :id | ||
field :retro_rating, Integer, null: true | ||
field :retro_text, null: true | ||
field :skip_retro, Boolean | ||
end |
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,74 @@ | ||
import React from 'react'; | ||
import { PageProps } from '../../../data.d'; | ||
import { useTranslate } from '../../frontend/util/dependencies'; | ||
import { Stack } from '../../frontend/components/stack/stack'; | ||
import { Button } from '../../frontend/components/button/button'; | ||
import { useForm } from '@nerdgeschoss/react-use-form-library'; | ||
import { TextField } from '../../frontend/components/text_field/text_field'; | ||
import { useReaction } from '../../frontend/sprinkles/reaction'; | ||
import { useModalInfo } from '../../frontend/components/modal/modal'; | ||
import { NumberField } from '../../frontend/components/number_field/number_field'; | ||
import { Checkbox } from '../../frontend/components/checkbox/checkbox'; | ||
|
||
export default function ({ | ||
data: { feedback }, | ||
}: PageProps<'sprint_feedbacks/edit_retro'>): JSX.Element { | ||
const t = useTranslate(); | ||
const reaction = useReaction(); | ||
const modal = useModalInfo(); | ||
const { fields, valid, onSubmit } = useForm({ | ||
model: { | ||
retroRating: feedback.retroRating ?? 5, | ||
retroText: feedback.retroText ?? '', | ||
skipRetro: feedback.skipRetro, | ||
}, | ||
validations: { | ||
retroRating: ({ model }) => | ||
model.skipRetro || model.retroRating ? [] : ['required'], | ||
retroText: ({ model }) => | ||
model.skipRetro || model.retroText ? [] : ['required'], | ||
}, | ||
onSubmit: async ({ model }) => { | ||
const sprint_feedback = model.skipRetro | ||
? { skipRetro: true, retroText: null, retroRating: null } | ||
: { | ||
skipRetro: false, | ||
retroText: model.retroText, | ||
retroRating: model.retroRating, | ||
}; | ||
await reaction.call({ | ||
path: `/sprint_feedbacks/${feedback.id}/update_retro`, | ||
method: 'POST', | ||
params: { sprint_feedback }, | ||
refresh: true, | ||
}); | ||
modal.close(); | ||
}, | ||
}); | ||
|
||
return ( | ||
<Stack> | ||
<Checkbox | ||
{...fields.skipRetro} | ||
label={t('sprint_feedbacks.edit_retro.skip')} | ||
/> | ||
{!fields.skipRetro.value && ( | ||
<> | ||
<NumberField | ||
{...fields.retroRating} | ||
label={t('sprint_feedbacks.edit_retro.rating')} | ||
/> | ||
<TextField | ||
{...fields.retroText} | ||
label={t('sprint_feedbacks.edit_retro.text')} | ||
/> | ||
</> | ||
)} | ||
<Button | ||
title={t('sprint_feedbacks.edit_retro.save')} | ||
disabled={!valid} | ||
onClick={onSubmit} | ||
/> | ||
</Stack> | ||
); | ||
} |
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.