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

Create react-select package #20944

Merged
merged 12 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from 9 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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ packages/react-popover/ @microsoft/teams-prg
packages/react-portal/ @microsoft/teams-prg
packages/react-provider/ @microsoft/teams-prg
packages/react-radio/ @microsoft/cxe-red
packages/react-select/ @microsoft/cxe-coastal @smhigley
packages/react-slider/ @microsoft/cxe-coastal @micahgodbolt
packages/react-spinner/ @microsoft/cxe-red @tomi-msft
packages/react-switch/ @microsoft/cxe-red @behowell @khmakoto @ecraig12345 @czearing
Expand Down
3 changes: 3 additions & 0 deletions packages/react-select/.babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["annotate-pure-calls", "@babel/transform-react-pure-annotations"]
smhigley marked this conversation as resolved.
Show resolved Hide resolved
}
4 changes: 4 additions & 0 deletions packages/react-select/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["plugin:@fluentui/eslint-plugin/react"],
"root": true
}
28 changes: 28 additions & 0 deletions packages/react-select/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.storybook/
.vscode/
bundle-size/
config/
coverage/
e2e/
etc/
node_modules/
src/
temp/
__fixtures__
__mocks__
__tests__

*.api.json
*.log
*.spec.*
*.stories.*
*.test.*
*.yml

# config files
*config.*
*rc.*
.editorconfig
.eslint*
.git*
.prettierignore
14 changes: 14 additions & 0 deletions packages/react-select/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const rootMain = require('../../../.storybook/main');

module.exports = /** @type {Omit<import('../../../.storybook/main'), 'typescript'|'babel'>} */ ({
...rootMain,
stories: [...rootMain.stories, '../src/**/*.stories.mdx', '../src/**/*.stories.@(ts|tsx)'],
addons: [...rootMain.addons],
webpackFinal: (config, options) => {
const localConfig = { ...rootMain.webpackFinal(config, options) };

// add your own webpack tweaks if needed

return localConfig;
},
});
7 changes: 7 additions & 0 deletions packages/react-select/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as rootPreview from '../../../.storybook/preview';

/** @type {typeof rootPreview.decorators} */
export const decorators = [...rootPreview.decorators];

/** @type {typeof rootPreview.parameters} */
export const parameters = { ...rootPreview.parameters };
10 changes: 10 additions & 0 deletions packages/react-select/.storybook/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "",
"allowJs": true,
"checkJs": true,
"types": ["static-assets", "environment", "storybook__addons"]
},
"include": ["../src/**/*.stories.ts", "../src/**/*.stories.tsx", "*.js"]
}
4 changes: 4 additions & 0 deletions packages/react-select/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@fluentui/react-select",
"entries": []
}
1 change: 1 addition & 0 deletions packages/react-select/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Change Log - @fluentui/react-select
15 changes: 15 additions & 0 deletions packages/react-select/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@fluentui/react-select

Copyright (c) Microsoft Corporation

All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note: Usage of the fonts and icons referenced in Fluent UI React is subject to the terms listed at https://aka.ms/fluentui-assets-license
9 changes: 9 additions & 0 deletions packages/react-select/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @fluentui/react-select

**React Select components for [Fluent UI React](https://developer.microsoft.com/en-us/fluentui)**

The Select component provides a styled wrapper around the native `<select>` element. It is recommended over Combobox when features like filtering and virtualization are not required. It provides better cross-platform functionality particularly on mobile, and better accessibility.

## STATUS: WIP 🚧

These are not production-ready components and **should never be used in product**. This space is useful for testing new components whose APIs might change before final release.
7 changes: 7 additions & 0 deletions packages/react-select/bundle-size/Select.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Select } from '@fluentui/react-select';

console.log(Select);

export default {
name: 'Select',
};
4 changes: 4 additions & 0 deletions packages/react-select/config/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"extends": "@fluentui/scripts/api-extractor/api-extractor.common.json"
}
5 changes: 5 additions & 0 deletions packages/react-select/config/api-extractor.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"extends": "./api-extractor.json",
"mainEntryPointFilePath": "<projectFolder>/dist/packages/<unscopedPackageName>/src/index.d.ts"
}
7 changes: 7 additions & 0 deletions packages/react-select/config/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** Jest test setup file. */

const { configure } = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');

// Configure enzyme.
configure({ adapter: new Adapter() });
50 changes: 50 additions & 0 deletions packages/react-select/etc/react-select.api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## API Report File for "@fluentui/react-select"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts

import type { ComponentProps } from '@fluentui/react-utilities';
import type { ComponentState } from '@fluentui/react-utilities';
import type { ForwardRefComponent } from '@fluentui/react-utilities';
import * as React_2 from 'react';
import type { Slot } from '@fluentui/react-utilities';

// @public
export const renderSelect_unstable: (state: SelectState) => JSX.Element;

// @public
export const Select: ForwardRefComponent<SelectProps>;

// @public (undocumented)
export const selectClassName = "fui-Select";

// @public (undocumented)
export interface SelectCommons {
appearance?: 'outline' | 'underline' | 'filledDarker' | 'filledLighter';
inline?: boolean;
size?: 'small' | 'medium' | 'large';
}

// @public (undocumented)
export type SelectProps = Omit<ComponentProps<Partial<SelectSlots>, 'select'>, 'size'> & SelectCommons;

// @public (undocumented)
export type SelectSlots = {
root: NonNullable<Slot<'span'>>;
select: NonNullable<Slot<'select'>>;
icon: Slot<'span'>;
};

// @public (undocumented)
export type SelectState = ComponentState<SelectSlots> & Required<SelectCommons>;

// @public
export const useSelect_unstable: (props: SelectProps, ref: React_2.Ref<HTMLSelectElement>) => SelectState;

// @public
export const useSelectStyles_unstable: (state: SelectState) => SelectState;

// (No @packageDocumentation comment for this package)

```
21 changes: 21 additions & 0 deletions packages/react-select/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @ts-check

/**
* @type {jest.InitialOptions}
*/
module.exports = {
displayName: 'react-select',
preset: '../../jest.preset.js',
globals: {
'ts-jest': {
tsConfig: '<rootDir>/tsconfig.spec.json',
diagnostics: false,
},
},
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
coverageDirectory: './coverage',
setupFilesAfterEnv: ['./config/tests.js'],
snapshotSerializers: ['@griffel/jest-serializer'],
};
3 changes: 3 additions & 0 deletions packages/react-select/just.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { preset } from '@fluentui/scripts';

preset();
65 changes: 65 additions & 0 deletions packages/react-select/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "@fluentui/react-select",
"version": "9.0.0-beta.0",
"description": "Fluent UI React Select component",
"private": true,
"main": "lib-commonjs/index.js",
"module": "lib/index.js",
"typings": "lib/index.d.ts",
"sideEffects": false,
"repository": {
"type": "git",
"url": "https://github.com/microsoft/fluentui"
},
"license": "MIT",
"scripts": {
"build": "just-scripts build",
"bundle-size": "bundle-size measure",
"clean": "just-scripts clean",
"code-style": "just-scripts code-style",
"just": "just-scripts",
"lint": "just-scripts lint",
"start": "yarn storybook",
"test": "jest --passWithNoTests",
"docs": "api-extractor run --config=config/api-extractor.local.json --local",
"build:local": "tsc -p ./tsconfig.lib.json --module esnext --emitDeclarationOnly && node ../../scripts/typescript/normalize-import --output ./dist/packages/react-select/src && yarn docs",
"bundle:storybook": "just-scripts storybook:build",
"storybook": "start-storybook",
"type-check": "tsc -b tsconfig.json"
},
"devDependencies": {
"@fluentui/eslint-plugin": "*",
"@fluentui/react-conformance": "*",
"@fluentui/react-conformance-griffel": "9.0.0-beta.0",
"@fluentui/scripts": "^1.0.0",
"@types/enzyme": "3.10.3",
"@types/enzyme-adapter-react-16": "1.0.3",
"@types/react": "16.9.42",
"@types/react-dom": "16.9.10",
"@types/react-test-renderer": "^16.0.0",
"enzyme": "~3.10.0",
"enzyme-adapter-react-16": "^1.15.0",
"react": "16.8.6",
"react-dom": "16.8.6",
"react-test-renderer": "^16.3.0"
},
"dependencies": {
"@fluentui/react-utilities": "9.0.0-beta.4",
"@griffel/react": "1.0.0",
"tslib": "^2.1.0"
},
"peerDependencies": {
"@types/react": ">=16.8.0 <18.0.0",
"@types/react-dom": ">=16.8.0 <18.0.0",
"react": ">=16.8.0 <18.0.0",
"react-dom": ">=16.8.0 <18.0.0"
},
"beachball": {
"tag": "beta",
"disallowedChangeTypes": [
"major",
"minor",
"patch"
]
}
}
1 change: 1 addition & 0 deletions packages/react-select/src/Select.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './components/Select/index';
1 change: 1 addition & 0 deletions packages/react-select/src/SelectDescription.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A Select allows one option to be selected from multiple options. The Select component is a wrapper around the native `<select>` element.
17 changes: 17 additions & 0 deletions packages/react-select/src/common/isConformant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { isConformant as baseIsConformant } from '@fluentui/react-conformance';
import type { IsConformantOptions, TestObject } from '@fluentui/react-conformance';
import griffelTests from '@fluentui/react-conformance-griffel';

export function isConformant<TProps = {}>(
testInfo: Omit<IsConformantOptions<TProps>, 'componentPath'> & { componentPath?: string },
) {
const defaultOptions: Partial<IsConformantOptions<TProps>> = {
asPropHandlesRef: true,
componentPath: module!.parent!.filename.replace('.test', ''),
disabledTests: ['has-docblock'],
skipAsPropTests: true,
extraTests: griffelTests as TestObject<TProps>,
};

baseIsConformant(defaultOptions, testInfo);
}
19 changes: 19 additions & 0 deletions packages/react-select/src/components/Select/Select.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as React from 'react';
import { render } from '@testing-library/react';
import { Select } from './Select';
import { isConformant } from '../../common/isConformant';

describe('Select', () => {
isConformant({
Component: Select,
displayName: 'Select',
primarySlot: 'select',
});

// TODO add more tests here, and create visual regression tests in /apps/vr-tests

it('renders the default state', () => {
const result = render(<Select />);
expect(result.container).toMatchSnapshot();
});
});
18 changes: 18 additions & 0 deletions packages/react-select/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as React from 'react';
import { useSelect_unstable } from './useSelect';
import { renderSelect_unstable } from './renderSelect';
import { useSelectStyles_unstable } from './useSelectStyles';
import type { SelectProps } from './Select.types';
import type { ForwardRefComponent } from '@fluentui/react-utilities';

/**
* Select component
*/
export const Select: ForwardRefComponent<SelectProps> = React.forwardRef((props, ref) => {
const state = useSelect_unstable(props, ref);

useSelectStyles_unstable(state);
return renderSelect_unstable(state);
});

Select.displayName = 'Select';
41 changes: 41 additions & 0 deletions packages/react-select/src/components/Select/Select.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';

export type SelectSlots = {
/*
* Wrapper for both the select and icon, renders as a `<span>`.
* The `className` and `style` props on `<Select>` are applied to this slot;
* All other top-level props are applied to the primary slot, `select`.
*/
root: NonNullable<Slot<'span'>>;

/** Primary slot: the actual `<select>` element */
select: NonNullable<Slot<'select'>>;

/** the icon, typically a down arrow */
icon: Slot<'span'>;
};

export interface SelectCommons {
/**
* Matches the Input sizes
* @default 'medium'
*/
size?: 'small' | 'medium' | 'large';

/**
* If true, the Select will have an inline `display`, allowing it to be inline with other content.
* By default, Select has block layout.
* @default false
*/
inline?: boolean;
smhigley marked this conversation as resolved.
Show resolved Hide resolved

/**
* Controls the colors and borders of the Select.
* @default 'outline'
*/
appearance?: 'outline' | 'underline' | 'filledDarker' | 'filledLighter';
Copy link
Member

Choose a reason for hiding this comment

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

how does darker and lighter work with high contrast or dark themes? Is there a need for color specific appearances?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They don't affect high contrast, but there are designs in the Figma spec for them in dark theme :). The appearance prop and what it controls is pretty much the exact same as for Input.

Copy link
Member

Choose a reason for hiding this comment

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

just worried about a future where the design changes a bit and 'darker' is no longer 'darker'. Curious if there was a discussion on how we named those variants in our system? Obviously it seems that it's used a bunch across different components, so would want to ensure consistency across all of them.

}

export type SelectProps = Omit<ComponentProps<Partial<SelectSlots>, 'select'>, 'size'> & SelectCommons;

export type SelectState = ComponentState<SelectSlots> & Required<SelectCommons>;
Loading