Skip to content
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

Basic SegmentedControl functionality #2108

Merged
merged 27 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
515a087
implements basic SegmentedControl functionality
mperrotti Jun 1, 2022
e0605c5
updates file structure
mperrotti Jun 1, 2022
d2c6d5a
adds SegmentedControl to drafts
mperrotti Jun 1, 2022
5f8bd3c
adds changeset
mperrotti Jun 1, 2022
52eee4e
fixes TypeScripts issues
mperrotti Jun 2, 2022
d10dd54
revert package-lock.json changes
mperrotti Jun 2, 2022
093e6a2
fixes SegmentedControl tests and updates snapshot
mperrotti Jun 2, 2022
2ae5107
style bug fixes
mperrotti Jun 2, 2022
54ca574
Update src/SegmentedControl/fixtures.stories.tsx
mperrotti Jun 6, 2022
054c2f0
improve visual design for hover and active states
mperrotti Jun 7, 2022
d0a00d4
Merge branch 'main' of github.com:primer/react into mp/segmented-cont…
mperrotti Jun 7, 2022
4958387
ARIA updates from Chelsea's feedback
mperrotti Jun 7, 2022
1f20ce9
Merge branch 'mp/segmented-control-basic' of github.com:primer/react …
mperrotti Jun 7, 2022
813e1bb
updates tests and snapshots
mperrotti Jun 7, 2022
afdeba8
Ignore *.test.tsx files in build types
colebemis Jun 7, 2022
563547b
Use named export for SegmentedControl
colebemis Jun 7, 2022
8dbf6aa
Update package-lock.json
colebemis Jun 7, 2022
c952c59
Merge branch 'mp/segmented-control-basic' of github.com:primer/react …
mperrotti Jun 8, 2022
b1253ec
Merge branch 'main' of github.com:primer/react into mp/segmented-cont…
mperrotti Jun 8, 2022
e14b6c0
updates lock file
mperrotti Jun 8, 2022
5278c3b
fixes checkExports test for SegmentedControl
mperrotti Jun 8, 2022
4ab92d0
design tweak for icon-only segmented control button
mperrotti Jun 8, 2022
8bb8ba3
Merge branch 'main' of github.com:primer/react into mp/segmented-cont…
mperrotti Jun 8, 2022
4695c84
Merge branch 'main' into mp/segmented-control-basic
colebemis Jun 9, 2022
8f22b04
Merge branch 'main' into mp/segmented-control-basic
mperrotti Jun 20, 2022
c03b4e1
Merge branch 'main' into mp/segmented-control-basic
mperrotti Jun 21, 2022
7ea6424
Merge branch 'main' into mp/segmented-control-basic
mperrotti Jun 23, 2022
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/SegmentedControl/SegmentedControl.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {render} from '@testing-library/react'
import {EyeIcon, FileCodeIcon, PeopleIcon} from '@primer/octicons-react'
import userEvent from '@testing-library/user-event'
import {behavesAsComponent, checkExports, checkStoriesForAxeViolations} from '../utils/testing'
import SegmentedControl from '.' // TODO: update import when we move this to the global index
import {SegmentedControl} from '.' // TODO: update import when we move this to the global index

const segmentData = [
{label: 'Preview', iconLabel: 'EyeIcon', icon: () => <EyeIcon aria-label="EyeIcon" />},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, is there a reason you're setting aria-label on the SVG and the button? I think by default the SVGs rendered by octicons are aria-hidden

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just used it so I could select it with React test utils.

I wouldn't do this in a real UI.

Expand Down
12 changes: 4 additions & 8 deletions src/SegmentedControl/SegmentedControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ const getSegmentedControlStyles = (props?: SegmentedControlProps) => ({
// TODO: implement `loading` prop
// TODO: log a warning if no `ariaLabel` or `ariaLabelledBy` prop is passed
// TODO: implement keyboard behavior to move focus using the arrow keys
const SegmentedControl: React.FC<SegmentedControlProps> = ({
children,
fullWidth,
onChange,
sx: sxProp = {},
...rest
}) => {
const Root: React.FC<SegmentedControlProps> = ({children, fullWidth, onChange, sx: sxProp = {}, ...rest}) => {
const {theme} = useTheme()
const selectedChildren = React.Children.toArray(children).map(
child =>
Expand Down Expand Up @@ -75,7 +69,9 @@ const SegmentedControl: React.FC<SegmentedControlProps> = ({
)
}

export default Object.assign(SegmentedControl, {
Root.displayName = 'SegmentedControl'

export const SegmentedControl = Object.assign(Root, {
Button,
IconButton: SegmentedControlIconButton
})
2 changes: 1 addition & 1 deletion src/SegmentedControl/examples.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Meta} from '@storybook/react'

import {BaseStyles, ThemeProvider} from '..'
import {ComponentProps} from '../utils/types'
import SegmentedControl from '.'
import {SegmentedControl} from '.'
import {EyeIcon, FileCodeIcon, PeopleIcon} from '@primer/octicons-react'

type Args = ComponentProps<typeof SegmentedControl>
Expand Down
2 changes: 1 addition & 1 deletion src/SegmentedControl/fixtures.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import {Meta} from '@storybook/react'

import {BaseStyles, Box, Text, ThemeProvider} from '../'
import SegmentedControl from '.'
import {SegmentedControl} from '.'

export default {
title: 'SegmentedControl/fixtures',
Expand Down
2 changes: 1 addition & 1 deletion src/SegmentedControl/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export {default} from './SegmentedControl'
export * from './SegmentedControl'
9 changes: 8 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@
// See also:
// - https://github.com/primer/react/issues/1163
// - https://github.com/primer/react/issues/1849
"exclude": ["**/*.stories.tsx", "script/**/*.ts", "src/__tests__/", "src/utils/test-*.tsx", "src/utils/testing.tsx"]
"exclude": [
"**/*.stories.tsx",
"**/*.test.tsx",
"script/**/*.ts",
"src/__tests__/",
"src/utils/test-*.tsx",
"src/utils/testing.tsx"
]
}