-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ab229e
commit 4488016
Showing
16 changed files
with
428 additions
and
1 deletion.
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
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
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
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
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
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,5 @@ | ||
dist/ | ||
node_modules/ | ||
package-lock.json | ||
pnpm-lock.yaml | ||
tsconfig.tsbuildinfo |
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,69 @@ | ||
NotGovUK - Standalone Input | ||
=========================== | ||
|
||
A single-line, form field with a submit button. | ||
|
||
|
||
Using this package | ||
------------------ | ||
|
||
First install the package into your project: | ||
|
||
```shell | ||
npm install -S @not-govuk/standalone-input | ||
``` | ||
|
||
Then use it in your code as follows: | ||
|
||
```js | ||
import React, { createElement as h } from 'react'; | ||
import StandaloneInput from '@not-govuk/standalone-input'; | ||
|
||
export const MyComponent = props => ( | ||
<StandaloneInput | ||
label="Your message" | ||
name="message" | ||
button="Send" | ||
/> | ||
); | ||
|
||
export default MyComponent; | ||
``` | ||
|
||
|
||
Working on this package | ||
----------------------- | ||
|
||
Before working on this package you must install its dependencies using | ||
the following command: | ||
|
||
```shell | ||
pnpm install | ||
``` | ||
|
||
|
||
### Testing | ||
|
||
Run the unit tests. | ||
|
||
```shell | ||
npm test | ||
``` | ||
|
||
|
||
### Building | ||
|
||
Build the package by compiling the TypeScript source code. | ||
|
||
```shell | ||
npm run build | ||
``` | ||
|
||
|
||
### Clean-up | ||
|
||
Remove any previously built files. | ||
|
||
```shell | ||
npm run clean | ||
``` |
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,43 @@ | ||
@import "@not-govuk/sass-base"; | ||
|
||
.not-govuk-standalone-input { | ||
display: flex; | ||
width: 100%; | ||
|
||
&__input { | ||
display: flex; | ||
flex: 0 1 auto; | ||
|
||
&.govuk-input { | ||
border-right-width: 0; | ||
|
||
&:focus { | ||
border-right-width: 2px; | ||
margin-right: -2px; | ||
z-index: 2; | ||
} | ||
} | ||
} | ||
|
||
&__button { | ||
$button-shadow-size: $govuk-border-width-form-element; | ||
|
||
display: flex; | ||
flex: 0 0 auto; | ||
margin-bottom: 0; | ||
|
||
&.govuk-button { | ||
margin-bottom: $button-shadow-size; | ||
} | ||
} | ||
|
||
&--fixed-width { | ||
.not-govuk-standalone-input__input { | ||
&.govuk-input { | ||
&:focus { | ||
margin-right: 0; | ||
} | ||
} | ||
} | ||
} | ||
} |
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,15 @@ | ||
'use strict'; | ||
|
||
const baseConfig = require('../../jest.config.base'); | ||
|
||
const config = { | ||
...baseConfig, | ||
collectCoverageFrom: [ | ||
'<rootDir>/src/**.{ts,tsx}', | ||
], | ||
testMatch: [ | ||
'<rootDir>/spec/**.{ts,tsx}' | ||
] | ||
}; | ||
|
||
module.exports = config; |
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,56 @@ | ||
{ | ||
"name": "@not-govuk/standalone-input", | ||
"version": "0.15.1", | ||
"description": "A single-line, form field with a submit button.", | ||
"main": "src/StandaloneInput.tsx", | ||
"sass": "assets/StandaloneInput.scss", | ||
"publishConfig": { | ||
"main": "dist/StandaloneInput.js", | ||
"typings": "dist/StandaloneInput.d.ts" | ||
}, | ||
"files": [ | ||
"/assets", | ||
"/dist" | ||
], | ||
"scripts": { | ||
"test": "NODE_OPTIONS=--experimental-vm-modules jest", | ||
"prepublishOnly": "npm run clean && npm run build", | ||
"build": "tsc", | ||
"clean": "rm -rf dist tsconfig.tsbuildinfo" | ||
}, | ||
"author": "Daniel A.C. Martin <[email protected]> (http://daniel-martin.co.uk/)", | ||
"license": "MIT", | ||
"keywords": [ | ||
"react-components" | ||
], | ||
"dependencies": { | ||
"@not-govuk/button": "workspace:^0.15.1", | ||
"@not-govuk/component-helpers": "workspace:^0.15.1", | ||
"@not-govuk/form-group": "workspace:^0.15.1", | ||
"@not-govuk/input": "workspace:^0.15.1", | ||
"@not-govuk/sass-base": "workspace:^0.15.1" | ||
}, | ||
"peerDependencies": { | ||
"@not-govuk/docs-components": "^0.15.1", | ||
"@storybook/addon-docs": "^6.5.16", | ||
"react": "^18.3.1" | ||
}, | ||
"peerDependenciesMeta": { | ||
"@not-govuk/docs-components": { | ||
"optional": true | ||
}, | ||
"@storybook/addon-docs": { | ||
"optional": true | ||
} | ||
}, | ||
"devDependencies": { | ||
"@mdx-js/react": "1.6.22", | ||
"@not-govuk/component-test-helpers": "workspace:^0.15.1", | ||
"@not-govuk/tag": "workspace:^0.15.1", | ||
"@types/react": "18.3.12", | ||
"jest": "29.7.0", | ||
"jest-environment-jsdom": "29.7.0", | ||
"ts-jest": "29.2.5", | ||
"typescript": "4.9.5" | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
components/standalone-input/spec/StandaloneInput.stories.mdx
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,110 @@ | ||
import { Meta, Preview, Props, Story } from '@storybook/addon-docs'; | ||
import { Tag } from '@not-govuk/tag'; | ||
import { StandaloneInput } from '../src/StandaloneInput'; | ||
import readMe from '../README.md'; | ||
|
||
<Meta | ||
title="Standalone input" | ||
component={ StandaloneInput } | ||
parameters={ { | ||
chromatic: { viewports: [640, 480] }, | ||
description: 'A single-line, form field with a submit button.', | ||
jest: ['StandaloneInput'], | ||
notes: readMe | ||
} } | ||
/> | ||
|
||
# Standalone input | ||
|
||
<p><Tag text="Unofficial" /> <Tag text="Experimental" /></p> | ||
|
||
A single-line, form field with a submit button. | ||
|
||
(Created to support the [Search box component] but may have other uses.) | ||
|
||
<Preview withToolbar> | ||
<Story name="StandaloneInput"> | ||
<StandaloneInput | ||
label="Your message" | ||
name="message" | ||
button="Send" | ||
/> | ||
</Story> | ||
</Preview> | ||
|
||
<Props of={ StandaloneInput } /> | ||
|
||
|
||
## Stories | ||
### Standard | ||
|
||
A standard Standalone input. | ||
|
||
<Preview> | ||
<Story name="Standard"> | ||
<StandaloneInput name="message" label="Message" /> | ||
</Story> | ||
</Preview> | ||
|
||
|
||
### Hint | ||
|
||
If you provide a hint, it will be displayed instead of the label. | ||
|
||
<Preview> | ||
<Story name="Hint"> | ||
<StandaloneInput name="message" label="Message" hint="What do you want to say?" /> | ||
</Story> | ||
</Preview> | ||
|
||
|
||
### Custom submit button text | ||
|
||
The text of the submit button is visually hidden, but can be customised for screen-readers. | ||
|
||
<Preview> | ||
<Story name="Custom button"> | ||
<StandaloneInput name="message" label="Message" button="Send" /> | ||
</Story> | ||
</Preview> | ||
|
||
|
||
### Fixed width | ||
|
||
<Preview> | ||
<Story name="Fixed width"> | ||
<StandaloneInput name="message" label="Message" width="10" /> | ||
</Story> | ||
</Preview> | ||
|
||
|
||
### Fluid width | ||
|
||
<Preview> | ||
<Story name="Fluid width"> | ||
<StandaloneInput name="message" label="Message" className="govuk-!-width-one-half" /> | ||
</Story> | ||
</Preview> | ||
|
||
|
||
### Error | ||
|
||
Currently errors are visually hidden, so it is best to avoid them. They will however be accessible to screen-readers, and the field will still be highlighted in red. | ||
|
||
<Preview> | ||
<Story name="Error"> | ||
<StandaloneInput name="message" label="Message" error="Something went wrong" /> | ||
</Story> | ||
</Preview> | ||
|
||
|
||
### Disabled | ||
|
||
<Preview> | ||
<Story name="Disabled"> | ||
<StandaloneInput name="message" label="Message" disabled /> | ||
</Story> | ||
</Preview> | ||
|
||
|
||
[Search box component]: /components?name=Search%20box |
Oops, something went wrong.