Skip to content

Commit

Permalink
Merge ecefb0a into 95dc202
Browse files Browse the repository at this point in the history
  • Loading branch information
strackoverflow authored Nov 1, 2023
2 parents 95dc202 + ecefb0a commit 684adb8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .changeset/five-crews-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@primer/react': patch
---

Select: Add support for `sx` prop

<!-- Changed components: Select -->
29 changes: 19 additions & 10 deletions src/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import styled from 'styled-components'
import TextInputWrapper, {StyledWrapperProps} from './internal/components/TextInputWrapper'
import {SxProp, merge, BetterSystemStyleObject} from './sx'

export type SelectProps = Omit<
Omit<React.ComponentPropsWithoutRef<'select'>, 'size'> & Omit<StyledWrapperProps, 'variant'>,
Expand Down Expand Up @@ -71,22 +72,30 @@ const ArrowIndicator = styled(ArrowIndicatorSVG)`
`

const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
({block, children, contrast, disabled, placeholder, size, required, validationStatus, ...rest}: SelectProps, ref) => (
(
{block, children, contrast, disabled, placeholder, size, required, validationStatus, sx = {}, ...rest}: SelectProps,
ref,
) => (
<TextInputWrapper
sx={{
overflow: 'hidden',
position: 'relative',
'@media screen and (forced-colors: active)': {
svg: {
fill: disabled ? 'GrayText' : 'FieldText',
},
},
}}
block={block}
contrast={contrast}
disabled={disabled}
size={size}
validationStatus={validationStatus}
sx={
merge(
{
overflow: 'hidden',
position: 'relative',
'@media screen and (forced-colors: active)': {
svg: {
fill: disabled ? 'GrayText' : 'FieldText',
},
},
},
sx as SxProp,
) as BetterSystemStyleObject
}
>
<StyledSelect
ref={ref}
Expand Down
16 changes: 16 additions & 0 deletions src/Select/Select.features.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,19 @@ export const Large = () => (
</FormControl>
</Box>
)

export const WithCustomStyling = () => (
<Box as="form">
<FormControl>
<FormControl.Label>Default label</FormControl.Label>
<Select sx={{borderRadius: '12px', border: '1px dashed #000000'}}>
<Select.Option value="one">Choice one</Select.Option>
<Select.Option value="two">Choice two</Select.Option>
<Select.Option value="three">Choice three</Select.Option>
<Select.Option value="four">Choice four</Select.Option>
<Select.Option value="five">Choice five</Select.Option>
<Select.Option value="six">Choice six</Select.Option>
</Select>
</FormControl>
</Box>
)

0 comments on commit 684adb8

Please sign in to comment.