-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make form controls more responsive. refactor form controls for …
…more control over style
- Loading branch information
1 parent
2c97811
commit 8fa0a46
Showing
2 changed files
with
182 additions
and
109 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { css } from '@emotion/react'; | ||
|
||
const Select = ({ disabled, ...props }) => ( | ||
<div | ||
css={css` | ||
height: 28px; | ||
display: grid; | ||
grid-template-areas: 'select'; | ||
align-items: center; | ||
width: 100%; | ||
min-width: 15ch; | ||
border: 1px solid var(--color-neutrals-500); | ||
border-radius: 0.25rem; | ||
padding: 0.25rem 0.5rem; | ||
cursor: pointer; | ||
position: relative; | ||
${disabled && | ||
css` | ||
cursor: not-allowed; | ||
opacity: 0.5; | ||
.light-mode & { | ||
background-color: var(--color-neutrals-100); | ||
} | ||
`} | ||
.dark-mode & { | ||
border: 1px solid var(--color-dark-300); | ||
background-color: var(--color-dark-300); | ||
} | ||
&::after { | ||
content: ''; | ||
grid-area: select; | ||
justify-self: end; | ||
width: 0.5rem; | ||
height: 0.25rem; | ||
clip-path: polygon(100% 0%, 0 0%, 50% 100%); | ||
background-color: var(--color-neutrals-700); | ||
.dark-mode & { | ||
background-color: var(--color-dark-700); | ||
} | ||
} | ||
`} | ||
> | ||
<select | ||
disabled={disabled} | ||
css={css` | ||
grid-area: select; | ||
appearance: none; | ||
background-color: transparent; | ||
border: none; | ||
padding: 0 1em 0 0; | ||
margin: 0; | ||
width: 100%; | ||
font-family: inherit; | ||
font-size: 14px; | ||
cursor: inherit; | ||
line-height: inherit; | ||
outline: none; | ||
&:focus + .focus-ring { | ||
position: absolute; | ||
top: -1px; | ||
left: -1px; | ||
right: -1px; | ||
bottom: -1px; | ||
border: 2px solid var(--color-brand-500); | ||
border-radius: inherit; | ||
} | ||
.dark-mode & { | ||
color: var(--color-dark-900); | ||
option { | ||
color: var(--color-dark-050); | ||
} | ||
} | ||
`} | ||
{...props} | ||
/> | ||
<span className="focus-ring" /> | ||
</div> | ||
); | ||
|
||
Select.propTypes = { | ||
disabled: PropTypes.bool, | ||
}; | ||
|
||
export default Select; |
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