-
Notifications
You must be signed in to change notification settings - Fork 370
feat(templates): add templates package #10110
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
587b2c7
feat(templates): add templates package
kmcfaul 8984560
revert v6 merge change from previous branch loc
kmcfaul 25f1a98
update template location to tab
kmcfaul 949e2db
update ver after rebase
kmcfaul 360998d
add descriptions to simple select
kmcfaul 5ff8330
pr feedback
kmcfaul 95d4e69
fix merge
kmcfaul 4bce50a
update docs-framework and code-editor
kmcfaul 4bb2a67
fix jest mocks
kmcfaul e32d9d0
back out codeeditor changes
kmcfaul b3a22e5
update templates version
kmcfaul f2c88d8
update templates version
kmcfaul 5d72064
pr updates
kmcfaul 6839ce2
yarn lockfile
kmcfaul e8ffa19
update options type
kmcfaul 540967c
Revert "yarn lockfile"
kmcfaul 8197774
lockfile revert
kmcfaul 458a079
update ver
kmcfaul 5597911
update type
kmcfaul f7ad4ca
doc build try 1
kmcfaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,2 @@ | ||
/deprecated | ||
/components |
This file contains hidden or 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,2 @@ | ||
dist/*.tsbuildinfo | ||
tsconfig.* |
This file contains hidden or 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,4 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. |
This file contains hidden or 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,42 @@ | ||
# @patternfly/react-templates | ||
|
||
This package provides wrapped Patternfly component demos with a streamlined API for ease of use. | ||
|
||
### Prerequisite | ||
|
||
#### Node Environment | ||
|
||
This project currently supports [Node Active LTS](https://github.com/nodejs/Release#release-schedule) releases. Please stay current with Node Active LTS when developing patternfly-react. | ||
|
||
For example, to develop with Node 18, use the following: | ||
|
||
``` | ||
nvm install 18 | ||
nvm use 18 | ||
``` | ||
|
||
This project also requires a Yarn version of >=1.6.0. The latest version can be installed from the [Yarn](https://yarnpkg.com/) home page. | ||
|
||
### Installing | ||
|
||
``` | ||
yarn add @patternfly/react-templates | ||
``` | ||
|
||
or | ||
|
||
``` | ||
npm install @patternfly/react-templates --save | ||
``` | ||
|
||
### Usage | ||
|
||
It's strongly advised to use the PatternFly Base CSS in your whole project, or some components may diverge in appearance: | ||
|
||
```js | ||
import '@patternfly/react-core/dist/styles/base.css'; | ||
``` | ||
|
||
```js | ||
import { SimpleSelect } from '@patternfly/react-templates'; | ||
``` |
This file contains hidden or 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,50 @@ | ||
{ | ||
"name": "@patternfly/react-templates", | ||
"version": "1.0.0-alpha.0", | ||
"description": "This package provides wrapped component demos for ease of use\n", | ||
"main": "dist/js/index.js", | ||
"module": "dist/esm/index.js", | ||
"types": "dist/esm/index.d.ts", | ||
"patternfly:src": "src/", | ||
"sideEffects": false, | ||
"publishConfig": { | ||
"access": "public", | ||
"tag": "alpha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/patternfly/patternfly-react.git" | ||
}, | ||
"keywords": [ | ||
"react", | ||
"patternfly", | ||
"templates" | ||
], | ||
"author": "Red Hat", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/patternfly/patternfly-react/issues" | ||
}, | ||
"homepage": "https://github.com/patternfly/patternfly-react/tree/main/packages/react-templates#readme", | ||
"scripts": { | ||
"build:umd": "rollup -c --environment IS_PRODUCTION", | ||
"build:single:packages": "node ../../scripts/build-single-packages.js --config single-packages.config.json", | ||
"clean": "rimraf dist components deprecated", | ||
"subpaths": "node ../../scripts/exportSubpaths.js --config subpaths.config.json" | ||
}, | ||
"dependencies": { | ||
"@patternfly/react-core": "^5.3.0-prerelease.17", | ||
"@patternfly/react-icons": "^5.3.0-prerelease.3", | ||
"@patternfly/react-styles": "^5.3.0-prerelease.3", | ||
"@patternfly/react-tokens": "^5.3.0-prerelease.3", | ||
"tslib": "^2.5.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^17 || ^18", | ||
"react-dom": "^17 || ^18" | ||
}, | ||
"devDependencies": { | ||
"rimraf": "^2.6.2", | ||
"typescript": "^4.7.4" | ||
} | ||
} |
This file contains hidden or 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,7 @@ | ||
const { name } = require('./package.json'); | ||
const baseConfig = require('../rollup.base'); | ||
|
||
module.exports = baseConfig({ | ||
packageName: name.replace('@patternfly/', ''), | ||
name: 'PatternFlyTemplates' | ||
}); |
This file contains hidden or 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,4 @@ | ||
{ | ||
"packageName": "@patternfly/react-templates", | ||
"exclude": ["dist/esm/deprecated/index.js", "dist/esm/next/index.js"] | ||
} |
100 changes: 100 additions & 0 deletions
100
packages/react-templates/src/components/Select/SelectSimple.tsx
This file contains hidden or 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,100 @@ | ||
import React from 'react'; | ||
import { Select, SelectList, SelectOption, SelectOptionProps } from '@patternfly/react-core/dist/esm/components/Select'; | ||
import { MenuToggle, MenuToggleElement } from '@patternfly/react-core/dist/esm/components/MenuToggle'; | ||
|
||
export interface SelectSimpleOption extends Omit<SelectOptionProps, 'content'> { | ||
/** Content of the select option. */ | ||
content: React.ReactNode; | ||
/** Value of the select option. */ | ||
value: string | number; | ||
} | ||
|
||
export interface SelectSimpleProps { | ||
/** @hide Forwarded ref */ | ||
innerRef?: React.Ref<any>; | ||
/** Initial options of the select. */ | ||
initialOptions?: SelectSimpleOption[]; | ||
/** Callback triggered on selection. */ | ||
onSelect?: (_event: React.MouseEvent<Element, MouseEvent>, selection: string | number) => void; | ||
/** Callback triggered when the select opens or closes. */ | ||
onToggle?: (nextIsOpen: boolean) => void; | ||
/** Flag indicating the select should be disabled. */ | ||
isDisabled?: boolean; | ||
/** Content of the toggle. Defaults to the selected option. */ | ||
toggleContent?: React.ReactNode; | ||
/** Width of the toggle */ | ||
toggleWidth?: string; | ||
} | ||
|
||
const SelectSimpleBase: React.FunctionComponent<SelectSimpleProps> = ({ | ||
innerRef, | ||
initialOptions, | ||
isDisabled, | ||
onSelect, | ||
onToggle, | ||
toggleContent, | ||
toggleWidth = '200px', | ||
...props | ||
}: SelectSimpleProps) => { | ||
const [isOpen, setIsOpen] = React.useState(false); | ||
const [selected, setSelected] = React.useState<string>('Select a value'); | ||
|
||
const simpleSelectOptions = initialOptions?.map((option) => { | ||
const { content, value, ...props } = option; | ||
const isSelected = selected.includes(`${value}`); | ||
return ( | ||
<SelectOption {...props} value={value} key={value} isSelected={isSelected}> | ||
{content} | ||
</SelectOption> | ||
); | ||
}); | ||
|
||
const onToggleClick = () => { | ||
onToggle && onToggle(!isOpen); | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
const _onSelect = (_event: React.MouseEvent<Element, MouseEvent> | undefined, value: string | number | undefined) => { | ||
onSelect && onSelect(_event, value); | ||
setSelected(value as string); | ||
setIsOpen(false); | ||
}; | ||
|
||
const toggle = (toggleRef: React.Ref<MenuToggleElement>) => ( | ||
<MenuToggle | ||
ref={toggleRef} | ||
onClick={onToggleClick} | ||
isExpanded={isOpen} | ||
isDisabled={isDisabled} | ||
style={ | ||
{ | ||
width: toggleWidth | ||
} as React.CSSProperties | ||
} | ||
> | ||
{toggleContent ? toggleContent : selected} | ||
</MenuToggle> | ||
); | ||
|
||
return ( | ||
<Select | ||
id="single-select" | ||
isOpen={isOpen} | ||
selected={selected} | ||
onSelect={_onSelect} | ||
onOpenChange={(isOpen) => setIsOpen(isOpen)} | ||
toggle={toggle} | ||
shouldFocusToggleOnSelect | ||
ref={innerRef} | ||
{...props} | ||
> | ||
<SelectList>{simpleSelectOptions}</SelectList> | ||
</Select> | ||
); | ||
}; | ||
|
||
export const SelectSimple = React.forwardRef((props: SelectSimpleProps, ref: React.Ref<any>) => ( | ||
<SelectSimpleBase {...props} innerRef={ref} /> | ||
)); | ||
|
||
SelectSimple.displayName = 'SelectSimple'; |
26 changes: 26 additions & 0 deletions
26
packages/react-templates/src/components/Select/examples/SelectSimpleDemo.tsx
This file contains hidden or 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,26 @@ | ||
import React from 'react'; | ||
import { Checkbox } from '@patternfly/react-core'; | ||
import { SelectSimple, SelectSimpleOption } from '@patternfly/react-templates'; | ||
|
||
export const SelectSimpleDemo: React.FunctionComponent = () => { | ||
const [isDisabled, setIsDisabled] = React.useState<boolean>(false); | ||
|
||
const initialOptions: SelectSimpleOption[] = [ | ||
{ content: 'Option 1', value: 'option1' }, | ||
{ content: 'Option 2', value: 'option2' }, | ||
{ content: 'Option 3', value: 'option3' } | ||
]; | ||
|
||
return ( | ||
<React.Fragment> | ||
<Checkbox | ||
id="toggle-disabled" | ||
label="isDisabled" | ||
isChecked={isDisabled} | ||
onChange={(_event, checked) => setIsDisabled(checked)} | ||
style={{ marginBottom: 20 }} | ||
/> | ||
<SelectSimple initialOptions={initialOptions} isDisabled={isDisabled} /> | ||
</React.Fragment> | ||
); | ||
}; |
23 changes: 23 additions & 0 deletions
23
packages/react-templates/src/components/Select/examples/SelectTemplates.md
This file contains hidden or 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,23 @@ | ||
--- | ||
id: Select | ||
section: components | ||
subsection: menus | ||
template: true | ||
beta: true | ||
propComponents: ['SimpleSelect'] | ||
kmcfaul marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--- | ||
|
||
Note: Templates live in their own package at [@patternfly/react-templates](https://www.npmjs.com/package/@patternfly/react-templates)! | ||
|
||
For custom use cases, please see the select component suite from [@patternfly/react-core](https://www.npmjs.com/package/@patternfly/react-core). | ||
|
||
import { SelectOption, Checkbox } from '@patternfly/react-core'; | ||
import { SelectSimple } from '@patternfly/react-templates'; | ||
|
||
## Select template examples | ||
|
||
### Simple | ||
|
||
```ts file="SelectSimpleDemo.tsx" | ||
|
||
``` |
This file contains hidden or 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 @@ | ||
export * from './SelectSimple'; |
This file contains hidden or 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 @@ | ||
export * from './Select'; |
This file contains hidden or 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 @@ | ||
export * from './components'; |
This file contains hidden or 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,4 @@ | ||
{ | ||
"packageName": "@patternfly/react-templates", | ||
"paths": ["components"] | ||
} |
This file contains hidden or 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,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist/js", | ||
"module": "commonjs", | ||
"tsBuildInfoFile": "dist/cjs.tsbuildinfo" | ||
} | ||
} |
This file contains hidden or 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,23 @@ | ||
{ | ||
"extends": "../tsconfig.base.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"outDir": "./dist/esm", | ||
"tsBuildInfoFile": "dist/esm.tsbuildinfo" | ||
}, | ||
"include": [ | ||
"./src/*", | ||
"./src/**/*" | ||
], | ||
"references": [ | ||
{ | ||
"path": "../react-core" | ||
}, | ||
{ | ||
"path": "../react-icons" | ||
}, | ||
{ | ||
"path": "../react-styles" | ||
} | ||
] | ||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -21,6 +21,9 @@ | |
}, | ||
{ | ||
"path": "./react-table/tsconfig.cjs.json" | ||
}, | ||
{ | ||
"path": "./react-templates/tsconfig.cjs.json" | ||
} | ||
] | ||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -21,6 +21,9 @@ | |
}, | ||
{ | ||
"path": "./react-table" | ||
}, | ||
{ | ||
"path": "./react-templates" | ||
} | ||
] | ||
} |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.