├── .gitignore
├── src
├── index.js
└── InlineInput.svelte
├── rollup.config.js
├── package.json
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | /dist/
4 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | export { default as default } from './InlineInput.svelte';
2 |
--------------------------------------------------------------------------------
/rollup.config.js:
--------------------------------------------------------------------------------
1 | import svelte from 'rollup-plugin-svelte';
2 | import resolve from '@rollup/plugin-node-resolve';
3 | import pkg from './package.json';
4 |
5 | const name = pkg.name
6 | .replace(/^(@\S+\/)?(svelte-)?(\S+)/, '$3')
7 | .replace(/^\w/, m => m.toUpperCase())
8 | .replace(/-\w/g, m => m[1].toUpperCase());
9 |
10 | export default {
11 | input: 'src/index.js',
12 | output: [
13 | { file: pkg.module, 'format': 'es' },
14 | { file: pkg.main, 'format': 'umd', name }
15 | ],
16 | plugins: [
17 | svelte(),
18 | resolve()
19 | ]
20 | };
21 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "svelte-inline-input",
3 | "version": "1.2.0",
4 | "description": "A Svelte component for inline editable inputs.",
5 | "svelte": "src/index.js",
6 | "module": "dist/index.mjs",
7 | "main": "dist/index.js",
8 | "unpkg": "dist/index.js",
9 | "scripts": {
10 | "build": "rollup -c",
11 | "prepublishOnly": "npm run build"
12 | },
13 | "author": "Uk Chukundah",
14 | "license": "MIT",
15 | "devDependencies": {
16 | "@rollup/plugin-node-resolve": "^6.0.0",
17 | "rollup": "^1.20.0",
18 | "rollup-plugin-svelte": "^5.0.0",
19 | "svelte": "^3.0.0"
20 | },
21 | "keywords": [
22 | "svelte",
23 | "inline",
24 | "editable",
25 | "input"
26 | ],
27 | "repository": {
28 | "type": "git",
29 | "url": "git+https://github.com/ukchukx/svelte-inline-input"
30 | },
31 | "files": [
32 | "src",
33 | "dist"
34 | ]
35 | }
36 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # svelte-inline-input
2 |
3 | > An inline editable input component for Svelte.
4 |
5 | Displays as text and becomes editable by clicking or tapping.
6 |
7 | 
8 |
9 | You can read how it was built [here](https://medium.com/@ukchukx/84274be1aa73)
10 |
11 | ## Installation
12 |
13 | ```js
14 | npm install svelte-inline-input
15 | ```
16 |
17 | ### Browser
18 |
19 | ```html
20 |
21 | ```
22 |
23 | ### Module
24 |
25 | ```js
26 | import InlineInput from 'svelte-inline-input';
27 | ```
28 |
29 | ## Usage
30 |
31 | Once installed, it can be used in a template as:
32 |
33 | ```html
34 |
35 | ```
36 |
37 | See the props table below for the available options.
38 |
39 | ### Props
40 |
41 | | Property | Type | Description | Default |
42 | |:--|:--|:--|:--|
43 | | type | string | The input type. Could be text, number, textarea or select | text |
44 | | placeholder | string | Text to be shown as a placeholder while there is no input | empty string |
45 | | labelClasses | string | CSS classes for the label element | empty string |
46 | | inputClasses | string | CSS classes for the input element | empty string |
47 | | rows | integer | Textarea rows | 2 |
48 | | cols | integer | Textarea columns | 20 |
49 | | options | array | Provides the options for selects. Each object should have the format `{label: x, value: x}` | [] |
50 |
51 | ### Events
52 |
53 | | Event | Description |
54 | |:--|:--|
55 | | blur | Fired when the input element loses focus. Also provides the input element's value |
56 |
57 | ## License
58 |
59 | [MIT](http://opensource.org/licenses/MIT)
60 |
--------------------------------------------------------------------------------
/src/InlineInput.svelte:
--------------------------------------------------------------------------------
1 |
61 |
62 | {#if editing && (isText || isNumber)}
63 |
72 | {:else if editing && isTextArea}
73 |
82 | {:else if editing && isSelect}
83 |
100 | {:else}
101 |
104 | {label}{#if isSelect}▼{/if}
105 |
106 | {/if}
107 |
--------------------------------------------------------------------------------