Skip to content

Commit 0ac9670

Browse files
authored
Merge pull request #118 from db-ui/feat-input
feat: input component
2 parents 1efd7c2 + 0d5159c commit 0ac9670

File tree

20 files changed

+788
-21
lines changed

20 files changed

+788
-21
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"update:components:button": "cpr ../core/source/_patterns/01-elements/buttons/button.scss packages/components/src/components/button/button.scss -o",
2828
"update:components:card": "cpr ../core/source/_patterns/02-components/cards/card.scss packages/components/src/components/card/card.scss -o",
2929
"update:components:cards": "cpr ../core/source/_patterns/02-components/cards/cards.scss packages/components/src/components/cards/cards.scss -o",
30+
"update:components:input": "cpr ../core/source/_patterns/02-components/input/input.scss packages/components/src/components/input/input.scss -o",
3031
"update:components": "npm-run-all -p update:core:*",
3132
"build:foundations": "npm run build --workspace=@db-ui/foundations",
3233
"build:components": "npm run build --workspace=@db-ui/components",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { DBInput, DBInputModule } from "./input";

packages/components/scripts/post-build/components.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
module.exports = [
2+
{
3+
name: "input",
4+
defaultStylePath: "components/input/input.css",
5+
},
6+
27
{
38
name: 'divider',
49
defaultStylePath: 'components/divider/divider.css',

packages/components/src/components/card/card.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
&[data-variant="ia"] {
4747
&:hover {
4848
cursor: pointer;
49-
box-shadow: $db-elevation-8;
49+
box-shadow: $db-elevation-4;
5050
}
5151

5252
&:active {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as DBInput } from "./input";
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { onMount, Show, useMetadata, useRef, useStore } from "@builder.io/mitosis";
2+
import { DBInputState, DBInputProps, iconVariants } from "./model";
3+
import { DBIcon } from '../icon';
4+
import "./input.scss";
5+
6+
useMetadata({
7+
isAttachedToShadowDom: false,
8+
component: {
9+
includeIcon: false,
10+
properties: [],
11+
},
12+
});
13+
14+
export default function DBInput(props: DBInputProps) {
15+
const textInputRef = useRef(null);
16+
const state = useStore<DBInputState>({
17+
_isValid: undefined,
18+
handleChange: (event) => {
19+
if (props.onChange) {
20+
props.onChange(event);
21+
}
22+
if (props.change) {
23+
props.change(event);
24+
}
25+
26+
if (textInputRef?.validity?.valid != state._isValid ) {
27+
state._isValid = textInputRef?.validity?.valid;
28+
if( props.validityChange ) {
29+
props.validityChange(textInputRef?.validity?.valid);
30+
}
31+
}
32+
},
33+
handleBlur: (event) => {
34+
if (props.onBlur) {
35+
props.onBlur(event);
36+
}
37+
if (props.blur) {
38+
props.blur(event);
39+
}
40+
},
41+
handleFocus: (event) => {
42+
if (props.onFocus) {
43+
props.onFocus(event);
44+
}
45+
if (props.focus) {
46+
props.focus(event);
47+
}
48+
}
49+
});
50+
51+
onMount(() => {
52+
if (props.stylePath) {
53+
state.stylePath = props.stylePath;
54+
}
55+
});
56+
57+
return (
58+
<div class={ 'db-input ' + (props.className || '') } data-variant={props.variant}>
59+
<Show when={state.stylePath}>
60+
<link rel="stylesheet" href={state.stylePath} />
61+
</Show>
62+
<Show when={props.iconBefore}>
63+
<DBIcon icon={props.iconBefore} className="icon-before" />
64+
</Show>
65+
<input
66+
ref={textInputRef}
67+
id={props.id}
68+
name={props.name}
69+
type={props.type || 'text'}
70+
placeholder={props.placeholder}
71+
aria-labelledby={props.id + '-label'}
72+
disabled={props.disabled}
73+
required={props.required}
74+
value={props.value}
75+
maxLength={props.maxLength}
76+
minLength={props.minLength}
77+
pattern={props.pattern}
78+
onChange={(event) => state.handleChange(event)}
79+
onBlur={(event) => state.handleBlur(event)}
80+
onFocus={(event) => state.handleFocus(event)}
81+
/>
82+
<label for={props.id} aria-hidden="true" id={props.id + '-label'}>
83+
<span>{props.label}</span>
84+
</label>
85+
<Show when={props.description}>
86+
<p className="description">{props.description}</p>
87+
</Show>
88+
<Show when={props.variant || props.required || props.pattern}>
89+
<DBIcon
90+
icon={props.variant && iconVariants[props.variant]}
91+
className="icon-input-state"
92+
/>
93+
</Show>
94+
<Show when={props.iconAfter}>
95+
<DBIcon icon={props.iconAfter} className="icon-after" />
96+
</Show>
97+
</div>
98+
);
99+
}

0 commit comments

Comments
 (0)