Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Datepicker Component (pc.datepicker) #237

Closed
Alek99 opened this issue Jan 10, 2023 · 4 comments · Fixed by #1126
Closed

Add Datepicker Component (pc.datepicker) #237

Alek99 opened this issue Jan 10, 2023 · 4 comments · Fixed by #1126
Labels
feature request A feature you wanted added to reflex good first issue Good for newcomers help wanted Extra attention is needed

Comments

@Alek99
Copy link
Member

Alek99 commented Jan 10, 2023

This would be a good first issue for someone as seen in our docs someone can wrap a datepicker.

For an intro on how to add a component see our docs: https://pynecone.io/docs/advanced-guide/wrapping-react.

The specs for this component would depend on the data picker library wrapped, or we could event use the base html datepicker.

@Alek99 Alek99 added enhancement Anything you want improved good first issue Good for newcomers labels Jan 10, 2023
@Alek99 Alek99 changed the title Add Datepicker Add Datepicker Component (pc.datepicker) Jan 10, 2023
@Alek99 Alek99 added help wanted Extra attention is needed feature request A feature you wanted added to reflex and removed enhancement Anything you want improved labels Jan 10, 2023
@qu3vipon
Copy link
Contributor

qu3vipon commented Jan 24, 2023

I did some research and couldn't complete this work, but here is a summary of my research.
Let me first reveal that I am not familiar with ReactJS.

  1. There are two different libraries: react-date-picker and react-datepicker

  2. I choose react-datepicker because its documentation is more detailed. Here is my code.

    class DatePicker(Component):
        library = "react-datepicker"
        tag = "DatePicker"  
      
        value: Var[str]  
        placeholder_text: Var[str]
    
        # date_format: Var[str]
        # time_format: Var[str]
        # locale: Var[str]
      
        @classmethod  
        def get_controlled_triggers(cls) -> Set[str]:  
            return {"on_change", "on_select"}  
      
        def _get_imports(self) -> ImportDict:  
            return utils.merge_imports(  
                super()._get_imports(), {"": {"react-datepicker/dist/react-datepicker.css"}},  
            )
    
    class State(pc.State): 
        date: str = ""  
      
    def index():  
        return pc.center(  
            pc.date_picker(  
                value=State.date,  
                on_change=State.set_date,  
                placeholder_text="Select a date..",  
            )  
        )
  3. After I compiled the app, it was rendered nicely. But when I selected a date, the value returned by the callback function was a string in iso format (i.e. 2023-01-01T00:00:00Z). I tried to format this string with the props the library provides, but every formatting prop didn't work.

Hope that it helps.

@FHU-yezi
Copy link
Contributor

Can we use datetime.fromisoformat to deal with this in Python side?

@qu3vipon
Copy link
Contributor

@FHU-yezi Yes, we can. But I'm not sure if we should start manipulating data types on the python side.
I hope there will be a better way of using the ReactJS library itself.

@iron3oxide
Copy link
Contributor

This thread may also be useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature you wanted added to reflex good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants