1
0
Fork 0
mirror of synced 2024-07-04 14:01:27 +12:00

Adding onChange functionality for typing date in field and tidy up

This commit is contained in:
Conor_Mack 2020-03-12 14:07:20 +00:00
parent 8f3c00bc81
commit 8076840fe1
8 changed files with 91 additions and 50 deletions

View file

@ -169,6 +169,16 @@
"description": "Material Design <tr>.", "description": "Material Design <tr>.",
"props": {} "props": {}
}, },
"DatePicker": {
"name": "DatePicker",
"description": "Material Design DatePicker",
"props": {
"date": "string",
"label": "string",
"onSelect": "event"
},
"tags": []
},
"H1": { "H1": {
"name": "H1", "name": "H1",
"description": "Sets the font properties as Roboto Headline1", "description": "Sets the font properties as Roboto Headline1",
@ -217,6 +227,18 @@
}, },
"tags": [] "tags": []
}, },
"IconButton": {
"onClick": "event",
"disabled": "bool",
"href": "string",
"icon": "string",
"size": {
"type":"options",
"options": ["small", "medium", "large"],
"default": "medium"
},
"tags": []
},
"Label": { "Label": {
"name": "Label", "name": "Label",
"description": "A simple label component that displays its text in the standard Roboto Material Design font", "description": "A simple label component that displays its text in the standard Roboto Material Design font",

View file

@ -17,21 +17,22 @@
import { Body1, Body2, Caption } from "../Typography" import { Body1, Body2, Caption } from "../Typography"
import { IconButton } from "../IconButton" import { IconButton } from "../IconButton"
let textFieldHeight = null
let menu let menu
let instance let instance
let textfieldValue = ""
let daysArr = [] let daysArr = []
let navDate = new Date() let navDate = new Date()
const weekdayMap = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"] const weekdayMap = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]
export let date = new Date() export let date = new Date()
export let open = true export let label = ""
export let onSelect = selectedDate => {}
onMount(() => { onMount(() => {
if (!!menu) { if (!!menu) {
instance = new MDCMenu(menu) instance = new MDCMenu(menu)
instance.open = true instance.open = false
instance.setFixedPostion = true instance.setFixedPostion = true
} }
}) })
@ -40,6 +41,7 @@
let month = getMonth(navDate) let month = getMonth(navDate)
let year = getYear(navDate) let year = getYear(navDate)
date = new Date(year, month, dayOfMonth) date = new Date(year, month, dayOfMonth)
onSelect(date)
} }
function addMonth() { function addMonth() {
@ -50,8 +52,21 @@
navDate = subMonths(navDate, 1) navDate = subMonths(navDate, 1)
} }
function openCalendar() { function openCalendar(isOpen) {
instance.open = true instance.open = isOpen === undefined ? !instance.open : isOpen
}
function textFieldChange(value) {
const isDate = /^\d{1,2}\/\d{1,2}\/\d{4}$/
if (isDate.test(value)) {
const [year, month, day] = value.split("/").reverse()
if (month > 0 && month <= 12 && (day > 0 && day <= 31)) {
date = new Date(year, month - 1, day)
navDate = date
openCalendar(true)
onSelect(date)
}
}
} }
$: dateMonthEnds = endOfMonth(navDate).getDate() $: dateMonthEnds = endOfMonth(navDate).getDate()
@ -71,23 +86,17 @@
dateMonthBegins > 5 && daysArr[daysArr.length - 1] > 30 ? 6 : 5 dateMonthBegins > 5 && daysArr[daysArr.length - 1] > 30 ? 6 : 5
$: sameMonthAndYear = $: sameMonthAndYear =
getMonth(date) === getMonth(navDate) && getYear(date) === getYear(navDate) getMonth(date) === getMonth(navDate) && getYear(date) === getYear(navDate)
$: console.log(textFieldHeight)
</script> </script>
<!--
TODO: Add transition effects to toggling of calendar
TODO: Bug - August 2020 has too many rows. find out why
TODO: Bug - make out transition of date bg colour instantaneous
-->
<div class="mdc-menu-surface--anchor"> <div class="mdc-menu-surface--anchor">
<Textfield <Textfield
bind:tfHeight={textFieldHeight} {label}
onChange={textFieldChange}
value={selectedDate} value={selectedDate}
trailingIcon={true} trailingIcon={true}
useIconButton={true} useIconButton={true}
iconButtonClick={openCalendar} iconButtonClick={openCalendar}
icon="calendar_today" icon="calendar_today" />
label="Select Date" />
<div <div
bind:this={menu} bind:this={menu}
@ -118,20 +127,16 @@
{#each daysArr as day, i} {#each daysArr as day, i}
<div <div
use:ripple use:ripple
style={i === 0 ? `grid-column-start: ${dayStart}` : ``}
on:click={() => selectDate(day)} on:click={() => selectDate(day)}
class={`bbmd-day ${dayOfSelectedDate === day && sameMonthAndYear ? 'selected' : ''}`}> class={`bbmd-day ${dayOfSelectedDate === day && sameMonthAndYear ? 'selected' : ''}`}>
{#if i === 0} <Body2 text={day} />
<div style={`grid-column-start: ${dateMonthBegins}`}>
<Body2 text={day} />
</div>
{:else}
<Body2 text={day} />
{/if}
</div> </div>
{/each} {/each}
</div> </div>
</div> </div>
<!-- Superfluous but necessary to keep the menu instance sweet -->
<ul class="mdc-list" role="menu" /> <ul class="mdc-list" role="menu" />
</div> </div>
</div> </div>
@ -157,10 +162,6 @@
grid-gap: 5px; grid-gap: 5px;
} }
.calendar-container > div {
/* border: 1px solid red; */
}
.week-days { .week-days {
display: grid; display: grid;
grid-template-columns: repeat(7, 1fr); grid-template-columns: repeat(7, 1fr);
@ -174,8 +175,4 @@
.centreText { .centreText {
text-align: center; text-align: center;
} }
span {
margin: auto;
}
</style> </style>

View file

@ -2,7 +2,7 @@
@import "@material/theme/mixins"; @import "@material/theme/mixins";
.bbmd-day { .bbmd-day {
transition: background-color 0.5s ease-in; transition: background-color .25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
display: flex; display: flex;
border-radius: 50%; border-radius: 50%;
justify-content: center; justify-content: center;

View file

@ -4,6 +4,8 @@
const cb = new ClassBuilder("icon-button") const cb = new ClassBuilder("icon-button")
let on = false
export let _bb export let _bb
export let context = "" export let context = ""
export let onClick = () => {} export let onClick = () => {}
@ -13,6 +15,11 @@
export let onIcon = "" //on state icon for toggle button export let onIcon = "" //on state icon for toggle button
export let size = "medium" export let size = "medium"
function onButtonClick() {
open = !open
onClick()
}
$: isToggleButton = !!icon && !!onIcon $: isToggleButton = !!icon && !!onIcon
$: useLinkButton = !!href $: useLinkButton = !!href
@ -22,20 +29,10 @@
</script> </script>
{#if useLinkButton} {#if useLinkButton}
<a on:click={onClick} class={iconBtnClass} {href} {disabled}> <a
{#if isToggleButton} on:click={onButtonClick}
<i
use:ripple
class="material-icons mdc-icon-button__icon mdc-icon-button__icon--on">
{onIcon}
</i>
<i use:ripple class="material-icons mdc-icon-button__icon">{icon}</i>
{:else}{icon}{/if}
</a>
{:else}
<button
on:click={onClick}
class={iconBtnClass} class={iconBtnClass}
{href}
{disabled} {disabled}
role="button" role="button"
tabindex="0"> tabindex="0">
@ -47,5 +44,23 @@
</i> </i>
<i use:ripple class="material-icons mdc-icon-button__icon">{icon}</i> <i use:ripple class="material-icons mdc-icon-button__icon">{icon}</i>
{:else}{icon}{/if} {:else}{icon}{/if}
</a>
{:else}
<button
on:click={onButtonClick}
class={iconBtnClass}
{disabled}
role="button"
aria-label="Add to favorites"
aria-pressed="false"
tabindex="0">
{#if isToggleButton}
<i use:ripple class="material-icons mdc-icon-button__icon">{icon}</i>
<i
use:ripple
class="material-icons mdc-icon-button__icon mdc-icon-button__icon--on">
{onIcon}
</i>
{:else}{icon}{/if}
</button> </button>
{/if} {/if}

View file

@ -2,7 +2,6 @@
.mdc-icon-button { .mdc-icon-button {
&.bbmd-mdc-icon-button--size-large { &.bbmd-mdc-icon-button--size-large {
@include mdc-icon-button-icon-size(24px); @include mdc-icon-button-icon-size(24px);
} }

View file

@ -18,6 +18,7 @@
List, List,
Select, Select,
DatePicker, DatePicker,
IconButton,
} = props } = props
let currentComponent let currentComponent
@ -36,6 +37,7 @@
Radiobutton, Radiobutton,
Radiobuttongroup, Radiobuttongroup,
DatePicker, DatePicker,
IconButton,
], ],
}, },
} }

View file

@ -209,6 +209,12 @@ export const props = {
DatePicker: { DatePicker: {
_component: "@budibase/materialdesign-components/DatePicker", _component: "@budibase/materialdesign-components/DatePicker",
_children: [], _children: [],
open: true, label: "Date of Admission",
onSelect: date => console.log("SELECTED DATE", date)
},
IconButton: {
_component: "@budibase/materialdesign-components/IconButton",
_children: [],
icon: "calendar_today",
}, },
} }

View file

@ -15,7 +15,6 @@
let tf = null let tf = null
export let tfHeight = null export let tfHeight = null
$: console.log("TF", tfHeight)
let tfInstance = null let tfInstance = null
onMount(() => { onMount(() => {
@ -98,10 +97,11 @@
function changed(e) { function changed(e) {
const val = e.target.value const val = e.target.value
value = val value = val
if (_bb.isBound(_bb.props.value)) { onChange(value)
_bb.setStateFromBinding(_bb.props.value, val) // if (_bb.isBound(_bb.props.value)) {
} // _bb.setStateFromBinding(_bb.props.value, val)
_bb.call(onChange, val) // }
// _bb.call(onChange, val)
} }
</script> </script>