@neovici/cosmoz-input 3.7.0 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { BaseInput } from './use-input';
2
2
  import { Render, ObjectFromList } from './render';
3
3
  declare const observedAttributes: string[];
4
- declare type CosmozInput = HTMLElement & ObjectFromList<typeof observedAttributes> & BaseInput & Render;
4
+ type CosmozInput = HTMLElement & ObjectFromList<typeof observedAttributes> & BaseInput & Render;
5
5
  export declare const Input: (host: CosmozInput) => import("lit-html").TemplateResult<1>;
6
6
  export {};
@@ -5,6 +5,7 @@ import { component } from 'haunted';
5
5
  import { useInput } from './use-input';
6
6
  import { useAllowedPattern } from './use-allowed-pattern';
7
7
  import { render, attributes } from './render';
8
+ import { getPlaceholder } from './util';
8
9
  const observedAttributes = [
9
10
  'type',
10
11
  'pattern',
@@ -16,7 +17,7 @@ const observedAttributes = [
16
17
  ...attributes,
17
18
  ];
18
19
  export const Input = (host) => {
19
- const { type = 'text', pattern, allowedPattern, autocomplete, value, placeholder, readonly, disabled, min, max, step, maxlength, } = host, { onChange, onFocus, onInput } = useInput(host);
20
+ const { type = 'text', pattern, allowedPattern, autocomplete, value, readonly, disabled, min, max, step, maxlength, } = host, { onChange, onFocus, onInput } = useInput(host);
20
21
  const onBeforeInput = useAllowedPattern(allowedPattern);
21
22
  return render(html `
22
23
  <input
@@ -26,7 +27,7 @@ export const Input = (host) => {
26
27
  type=${type}
27
28
  pattern=${ifDefined(pattern)}
28
29
  autocomplete=${ifDefined(autocomplete)}
29
- placeholder=${placeholder || ' '}
30
+ placeholder=${getPlaceholder(host)}
30
31
  ?readonly=${readonly}
31
32
  ?aria-disabled=${disabled}
32
33
  ?disabled=${disabled}
@@ -1,6 +1,6 @@
1
1
  import { BaseInput } from './use-input';
2
2
  import { Render, ObjectFromList } from './render';
3
3
  declare const observedAttributes: string[];
4
- declare type CosmozInput = HTMLElement & ObjectFromList<typeof observedAttributes> & BaseInput & Render;
4
+ type CosmozInput = HTMLElement & ObjectFromList<typeof observedAttributes> & BaseInput & Render;
5
5
  export declare const Textarea: (host: CosmozInput) => import("lit-html").TemplateResult<1>;
6
6
  export {};
package/dist/render.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare type ObjectFromList<T extends ReadonlyArray<string>, V = string> = {
1
+ export type ObjectFromList<T extends ReadonlyArray<string>, V = string> = {
2
2
  [K in T extends ReadonlyArray<infer U> ? U : never]: V;
3
3
  };
4
4
  export interface Render {
package/dist/render.js CHANGED
@@ -9,6 +9,7 @@ export const render = (control, { label, invalid, errorMessage }) => html `
9
9
  <div class="wrap" part="wrap">
10
10
  <slot name="prefix"></slot>
11
11
  <div class="control" part="control">
12
+ <slot name="control"></slot>
12
13
  ${control}
13
14
  ${when(label, () => html `<label for="input" part="label">${label}</label>`)}
14
15
  </div>
package/dist/styles.js CHANGED
@@ -102,8 +102,10 @@ export const styles = css `
102
102
  transform: translateY(calc(var(--label-scale) * -100%))
103
103
  scale(var(--label-scale));
104
104
  }
105
- #input:not(:placeholder-shown):focus + label {
105
+ :host(:not(always-float-label):focus-within) #input::placeholder,
106
+ :host(:focus-within) label {
106
107
  color: var(--focused-color);
108
+ opacity: 1;
107
109
  }
108
110
 
109
111
  .line {
@@ -137,7 +139,7 @@ export const styles = css `
137
139
  }
138
140
 
139
141
  :host([no-label-float]) .float,
140
- :host([no-label-float]) #input:not(:placeholder-shown) + label {
142
+ :host([no-label-float]) label {
141
143
  display: none;
142
144
  }
143
145
 
@@ -190,7 +192,7 @@ export const styles = css `
190
192
  width: var(--width);
191
193
  min-width: calc(2ch + 0.25em);
192
194
  }
193
- :host([type="color"]) .line {
195
+ :host([type='color']) .line {
194
196
  display: none;
195
197
  }
196
198
  `;
package/dist/util.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ interface Props {
2
+ label?: string;
3
+ noLabelFloat?: boolean;
4
+ placeholder?: string;
5
+ }
6
+ export declare const getPlaceholder: ({ placeholder, noLabelFloat, label }: Props) => string;
7
+ export {};
package/dist/util.js ADDED
@@ -0,0 +1,3 @@
1
+ export const getPlaceholder = ({ placeholder, noLabelFloat, label }) => {
2
+ return (noLabelFloat ? label : undefined) || placeholder || ' ';
3
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-input",
3
- "version": "3.7.0",
3
+ "version": "3.9.0",
4
4
  "description": "A input web component",
5
5
  "keywords": [
6
6
  "lit-html",
@@ -79,10 +79,9 @@
79
79
  "@semantic-release/changelog": "^6.0.0",
80
80
  "@semantic-release/git": "^10.0.0",
81
81
  "@storybook/storybook-deployer": "^2.8.5",
82
- "@web/dev-server-storybook": "^0.5.1",
82
+ "@web/dev-server-storybook": "^0.7.0",
83
83
  "husky": "^8.0.0",
84
- "semantic-release": "^19.0.0",
85
- "sinon": "^14.0.0",
86
- "typescript": "^4.6.0"
84
+ "semantic-release": "^21.0.1",
85
+ "sinon": "^15.0.0"
87
86
  }
88
87
  }