Skip to content

Feat: migrate Radio from Javascript to Typescript #2382

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
44 changes: 0 additions & 44 deletions src/components/radio/Radio.js

This file was deleted.

43 changes: 0 additions & 43 deletions src/components/radio/Radio.stories.js

This file was deleted.

33 changes: 33 additions & 0 deletions src/components/radio/Radio.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { action } from '@storybook/addon-actions'
import { StoryFn, Meta } from '@storybook/react'
import Radio from './Radio.js'

const bigPicture = {
transform: 'scale(5)',
transformOrigin: 'top left'
}

const meta: Meta<typeof Radio> = {
title: 'Radio',
component: Radio
}

export default meta

export const Default: StoryFn<typeof Radio> = () => (
<div>
<Radio className='ma2' label='Click me!' onChange={action('Checked')} />
</div>
)

export const Disabled: StoryFn<typeof Radio> = () => (
<div>
<Radio label='Click me!' className='ma2' disabled onChange={action('Checked')} />
</div>
)

export const Big: StoryFn<typeof Radio> = () => (
<div>
<Radio style={bigPicture} label='Click me!' className='ma2' onChange={action('Checked')} />
</div>
)
36 changes: 36 additions & 0 deletions src/components/radio/Radio.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react'
import './Radio.css'

interface RadioProps {
className?: string
label?: React.ReactNode
disabled?: boolean
checked?: boolean
onChange: (checked: boolean) => void
[x: string]: any
}

const Radio: React.FC<RadioProps> = ({ className = '', label = '', disabled = false, checked = false, onChange, ...props }) => {
let combinedClassName = `Radio dib sans-serif ${className}`
if (!disabled) {
combinedClassName += ' pointer'
}

const change = (event: React.ChangeEvent<HTMLInputElement>) => {
onChange(event.target.checked)
}

return (
<label className={combinedClassName} {...props}>
<input className='absolute' type='checkbox' checked={checked} disabled={disabled} onChange={change} />
<span className='dib v-mid br-100 w1 h1 pa1 border-box pointer'>
<span className='db br-100 w-100 h-100 o-0 bg-aqua'/>
</span>
<span className='v-mid pl2'>
{label}
</span>
</label>
)
}

export default Radio
2 changes: 1 addition & 1 deletion src/files/modals/publish-modal/PublishModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Button from '../../../components/button/button.tsx'
import { Modal, ModalActions, ModalBody } from '../../../components/modal/Modal.js'
import Icon from '../../../icons/StrokeSpeaker.js'
import { connect } from 'redux-bundler-react'
import Radio from '../../../components/radio/Radio.js'
import Radio from '../../../components/radio/Radio.tsx'
import ProgressBar from '../../../components/progress-bar/ProgressBar.js'
import GlyphCopy from '../../../icons/GlyphCopy.js'
import GlyphTick from '../../../icons/GlyphTick.js'
Expand Down