@neovici/cosmoz-input 3.8.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.
@@ -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}
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.8.0",
3
+ "version": "3.9.0",
4
4
  "description": "A input web component",
5
5
  "keywords": [
6
6
  "lit-html",