SAP / ui5-webcomponents

UI5 Web Components - the enterprise-flavored sugar on top of native APIs! Build SAP Fiori user interfaces with the technology of your choice.
https://sap.github.io/ui5-webcomponents/
Apache License 2.0
1.54k stars 265 forks source link

[Calendar] What's the exact type of selectedDates in the Calendar component #1730

Closed SunnyWind closed 3 years ago

SunnyWind commented 4 years ago

In the storybook, it says the type of selectedDates property is unknown[], which is very unclear. image

On the other side, my editor tells me the type of the selectedDates is number[]. image

If I set the selectedDates to [Date.now()/1000], I'll get an error: image image

What kind of data should I pass to the Calendar component if I want to specify an initial date?

MarcusNotheis commented 4 years ago

Hi @SunnyWind,

I'm not sure what the correct prop type is to be honest - I've created an issue (https://github.com/SAP/ui5-webcomponents/issues/1677) to clarify.

Best regards, MArcus

MarcusNotheis commented 4 years ago

Hey @SunnyWind

I'm just copy-pasting Vladi's answer from the Web Components Team. Looks like you have to attach a ref to the Calender and set the current date via Javascript in a useEffect or componentDidMount/Update. Could you please explain what your use case of the Calendar is?

Best regards, Marcus

Indeed, ui5-calendar is intended to be a lower-level component, mainly used by other components. Therefore its API is not as user-friendly.

UI5 Web Components metadata entities of type Object or of multiple: true (hence Array) cannot be passed via attributes, but only via HTML properties. You can't bind them declaratively via React, only with JS.

myCalendar.selectedDates = [1588464000];

is what would work.

But if you have a strong case, we can redo the calendar to have calendar date items or something of that sort that you can pass as children.

Regards, Vladi

Originally posted by @vladitasev in https://github.com/SAP/ui5-webcomponents/issues/1677#issuecomment-634473436

SunnyWind commented 4 years ago

Thanks for your answer, which can solve my problem.

I want to replace the current calendar plugin (which is a YUI plugin) on our website with ui5-webcomponent calendar.

Just replacing the calendar widget will be easier compared with using the DatePicker (Less modifications to HTML construct).

MarcusNotheis commented 4 years ago

I think this is a valid use case to be honest - @vladitasev does this justify a rework of the Calender to have a more declarative API?

MarcusNotheis commented 4 years ago

As this issue is focusing on a UI5 Web Component, I'll forward this issue to the respective repository.

vladitasev commented 4 years ago

Hi @SunnyWind @MarcusNotheis

Yes, I think it makes sense to promote the Calendar as a real standalone component. We'll estimate what kind of effort will be required and we'll update you here.

Regards

vladitasev commented 4 years ago

The goal of the story is to make the calendar usable standalone. This would require all APIs to be re-evaluated and changed where necessary, it should have all necessary events, proper docs.

ilhan007 commented 4 years ago

Phase 1 - Make the ui5-calendar standalone and public component.

There is а private ui5-calendar web component that is internally used by the DatePicker, DateTimePicker and DateRangePicker. The task is to make it public, to ensure it is completely usable standalone. But also to review the current API and make it more user friendly if possible.

1. API to support

Note: timestamp and formatPattern should be private.

2. We would like to have single range selection.

Currently if you set the following:

calComponent.selectedDates = [1600041600, 1600128000, 1600214400, 1600300800, 1600387200, 1600473600, 1600560000, 1600646400, 1600732800, 1600819200, 1600905600]

You will get:

Screenshot 2020-09-03 at 4 17 22 PM

But, it is not possible to get it via user interaction. We have DateRangePicker, so some of the logic should be extracted from the DateRangePicker and implemented on Calendar level and then DateRangePicker would rely on the Calendar for this. If both components should communicate in this regards, it should be done via events.

3. Upon TAB the focus should move to the "selected day" or "today". Currently the button, that opens the Month Picker is the 1st element to get the focus. But as far as I researched, the order should be: the "selected day/today", Month Picker button and Year Picker button.

4. The components (DatePicker, DateTimePicker and DateRangePicker) using the Calendar should adopt the API changes (if any)

5. The component has a test page (Calendar.html) that need to be improved:

6. The component has a test spec (Calendar.spec.js) that might has to be adjusted.

7. Properly document - add overview section, import info, etc (refer to the existing components and the openui5 equivalent for the text), remove all @ since tags and provide just one for the entire class @ since 1.0.0-rc.10

8. Playground sample - create Calendar.sample.html with few examples that showcase the component

ilhan007 commented 4 years ago

Hello @SunnyWind

we introduced the Calendar as standalone component (ui5-calendar). The component is merged into the master, not yet released. This was the first step to achieve the goal. Now, we created a separate issue "Calendar: Declarative way of setting the selected days" that we will full-fill your request completely. You can track the progress here: https://github.com/SAP/ui5-webcomponents/issues/2528

BR, ilhan

ilhan007 commented 3 years ago

Hello @SunnyWind

we introduced the Calendar as standalone component (ui5-calendar). The component is merged into the master #2424, it is not yet released. This was the first step to achieve the goal. Now, we created a separate issue "Calendar: Declarative way of setting the selected days" that we will full-fill your request completely. You can track the progress here: #2528

BR, ilhan

SunnyWind commented 3 years ago

Hi @ilhan007

Fantastic 👍

I use ui5-webcomponent-react instead of the base lib. I'll try it if the new feature is applied in that library.

BRs, Ryan