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

feature: support Hightlight component #1079

Merged
merged 1 commit into from
May 26, 2023

Conversation

TaiJuWu
Copy link
Contributor

@TaiJuWu TaiJuWu commented May 24, 2023

All Submissions:

  • Have you followed the guidelines stated in CONTRIBUTING.md file?
  • Have you checked to ensure there aren't any other open Pull Requests for the desired changed?

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

New Feature Submission:

  • Does your submission pass the tests?
  • Have you linted your code locally prior to submission?

Changes To Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

After these steps, you're ready to open a pull request.

a. Give a descriptive title to your PR.

support Highlight component.
b. Describe your changes.
support Highlight component and you have to notice styles and style is different prop. Highlight uses styles.

c. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes (if such).

close #1048

@TaiJuWu TaiJuWu force-pushed the feature/highlight branch from 738e208 to 558719f Compare May 24, 2023 20:46
@Alek99 Alek99 self-requested a review May 24, 2023 23:11
@Alek99
Copy link
Member

Alek99 commented May 24, 2023

This code doesn't seem to be working for me can you provide an example?

@TaiJuWu
Copy link
Contributor Author

TaiJuWu commented May 25, 2023

This code doesn't seem to be working for me can you provide an example?

It's working fo me.
Is this example working for you?

import pynecone as pc

class State(pc.State):
    """The app state."""

    text: str = "With the Highlight component, you can spotlight, emphasize and accentuate words."
    query=['spotlight', 'emphasize', 'Accentuate']
    styles={ 'px': '2', 'py': '1', 'rounded': 'full', 'bg': 'teal.100' }
    
    
def index():
    """The main view."""
    return pc.heading(
        pc.highlight(State.text, query=State.query, styles=State.styles)
    )
    
app = pc.App(state=State)
app.add_page(index)
app.compile()

@Lendemor
Copy link
Collaborator

I think the Highlight component should provide a default styles in case the user didn't provide it.

@TaiJuWu TaiJuWu force-pushed the feature/highlight branch from 558719f to a12196c Compare May 25, 2023 14:44
@TaiJuWu
Copy link
Contributor Author

TaiJuWu commented May 25, 2023

I think the Highlight component should provide a default styles in case the user didn't provide it.

In chakra highlight does not have default value.
But I absolutely agree with you so I give a default value.

@TaiJuWu TaiJuWu force-pushed the feature/highlight branch 2 times, most recently from ef67cb3 to 418a25c Compare May 25, 2023 14:54
@Alek99
Copy link
Member

Alek99 commented May 25, 2023

For this component should we take the stye props and pass them into the style dict similar to how it's done in code block. This would allow code like

class State(pc.State):
    """The app state."""

    text: str = "With the Highlight component, you can spotlight, emphasize and accentuate words."
    query=['spotlight', 'emphasize', 'Accentuate']
    styles={ 'px': '2', 'py': '1', 'rounded': 'full', 'bg': 'teal.100' }
    
    def add_query(self, query: str):
        """Add a query to the list of queries."""
        self.query.append(query)
    
def index():
    """The main view."""
    
    return pc.vstack(
        pc.input(on_blur=State.add_query),
        pc.heading(
            pc.highlight(
                State.text, 
                query=State.query, 
                bg = "green",
                color = "red",
                px = "2",
                py = "1",
                rounded = "full",

            )
        ),
    )

https://github.com/pynecone-io/pynecone/blob/e9ca1fd03b7d1c3caade682bd9f1f2dca10f268a/pynecone/components/datadisplay/code.py#L52-L75

@TaiJuWu TaiJuWu force-pushed the feature/highlight branch from 418a25c to 149329e Compare May 25, 2023 21:50
@TaiJuWu
Copy link
Contributor Author

TaiJuWu commented May 26, 2023

For this component should we take the stye props and pass them into the style dict similar to how it's done in code block. This would allow code like

class State(pc.State):
    """The app state."""

    text: str = "With the Highlight component, you can spotlight, emphasize and accentuate words."
    query=['spotlight', 'emphasize', 'Accentuate']
    styles={ 'px': '2', 'py': '1', 'rounded': 'full', 'bg': 'teal.100' }
    
    def add_query(self, query: str):
        """Add a query to the list of queries."""
        self.query.append(query)
    
def index():
    """The main view."""
    
    return pc.vstack(
        pc.input(on_blur=State.add_query),
        pc.heading(
            pc.highlight(
                State.text, 
                query=State.query, 
                bg = "green",
                color = "red",
                px = "2",
                py = "1",
                rounded = "full",

            )
        ),
    )

It's working right now.

@TaiJuWu TaiJuWu force-pushed the feature/highlight branch from 149329e to 827dc39 Compare May 26, 2023 01:25
@TaiJuWu TaiJuWu force-pushed the feature/highlight branch from 827dc39 to 91efaec Compare May 26, 2023 01:28
Copy link
Contributor

@picklelo picklelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@picklelo picklelo merged commit 2903d7a into reflex-dev:main May 26, 2023
@TaiJuWu TaiJuWu deleted the feature/highlight branch May 26, 2023 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Highlight Component
4 participants