Skip to content

Conversation

@wesruv
Copy link
Contributor

@wesruv wesruv commented Oct 8, 2021

Need docs update and tests still, also think we can add a disabled state if it can't find what it should be copying.

For this proof o concept, see the comments I made below, and then check out the demo page here:
https://deploy-preview-1795--patternfly-elements.netlify.app/elements/pfe-clipboard/demo/

Related issues

@github-actions github-actions bot added demo Updating demo pages functionality Functionality, typically pertaining to the JavaScript. labels Oct 8, 2021
@wesruv wesruv force-pushed the 1794-allow-pfe-clipboard-to-copy-arbitrary-things branch from 4e17be8 to 23a2c23 Compare October 8, 2021 18:15
@netlify
Copy link

netlify bot commented Oct 8, 2021

✔️ Deploy Preview for patternfly-elements ready!

🔨 Explore the source changes: 4e17be8

🔍 Inspect the deploy log: https://app.netlify.com/sites/patternfly-elements/deploys/616089f4f6f41c000714f318

😎 Browse the preview: https://deploy-preview-1795--patternfly-elements.netlify.app

@github-actions github-actions bot added the AT passed Automated testing has passed label Oct 8, 2021
@netlify
Copy link

netlify bot commented Oct 8, 2021

✔️ Deploy Preview for patternfly-elements ready!

🔨 Explore the source changes: d83a5c5

🔍 Inspect the deploy log: https://app.netlify.com/sites/patternfly-elements/deploys/618581127320370007f8ec2e

😎 Browse the preview: https://deploy-preview-1795--patternfly-elements.netlify.app/components/clipboard

@bennypowers
Copy link
Member

Are we interested in using the Clipboard API to copy multimedia objects in supporting browsers?

@github-actions github-actions bot added the tests Related to testing label Oct 14, 2021
@wesruv
Copy link
Contributor Author

wesruv commented Oct 14, 2021

@bennypowers that'd be awesome! 🤔 Though I don't know that there's any use case for it yet.
I want this PR for a specific feature in my main project, if we think adding that would cause this PR to take longer before it's merged, I'd prefer we did it in a separate PR.

…ithub.com:patternfly/patternfly-elements into 1794-allow-pfe-clipboard-to-copy-arbitrary-things
@github-actions github-actions bot added the styles An issue or PR pertaining only to CSS/Sass label Oct 15, 2021
@wesruv wesruv changed the title WIP: Added proof of concept for copying arbitrary content feat: Added proof of concept for copying arbitrary content Oct 15, 2021
@wesruv
Copy link
Contributor Author

wesruv commented Oct 15, 2021

EDIT
Nevermind the question in this comment, see below comment, discussed this with the DXP CPFED folks.


The code is good to go as far as I'm concerned, but I it still needs docs. Wanted to bounce this issue off folks before I wrote the docs:

I added a few disabled states for when:

  • target='property' and el.contentToCopy is not set
    • I added a getter and setter so I don't think there's a chance the component will be disabled if that value is set
  • EDIT No longer doing this /EDIT target='selector' and element in selector can't be found
    • This one is not fool proof. The code checks to see if the selector finds an element on connectedCallback, on DOMContentLoaded, and load, but if the content is injected dynamically the site would have to call el.checkForCopyTarget()
    • It also runs checkForCopyTarget() when the target attribute changes, which helps with the issue in the previous bullet

The only other ways of checking to see if the element exists would be heavy... like a MutationObserver on the document 🤢 ...

Do you all think this is good enough? Is there a 'cool kid' way to handle that 'not fool proof' concern that I'm missing?

Discussed with Kyle Buchanan, Michael Clayton, and other CPFED folks, guarding against the HTML element that will have it's text copied isn't really worth it. There isn't a good way to know that it _should_ be disabled and then _should_ be enabled later.
Better to leave it to the click event, and hopefully things were setup so it'll work when the user clicks on it
@wesruv
Copy link
Contributor Author

wesruv commented Oct 15, 2021

The code is good to go as far as I'm concerned, but I it still needs docs. Wanted to bounce this issue off folks before I wrote the docs:
...
Do you all think this is good enough? Is there a 'cool kid' way to handle that 'not fool proof' concern that I'm missing?

Discussed this with Kyle Buchanan, Michael Clayton, and other CPFED folks, and it feels like checking to see if an element exists isn't worth it. We can know if the property is set, but if an element exists is too hairy, and not a necessary thing to guard against.

@github-actions github-actions bot added the docs Documentation updates label Oct 15, 2021
@wesruv wesruv changed the title feat: Added proof of concept for copying arbitrary content feat: Make it so PFE-Clipboard can copy arbitrary content Oct 15, 2021
@coreyvickery
Copy link
Collaborator

@heyMP Please ensure these colors are integrated or let me know if there is another issue where I can put this information.

Light theme

  • Icon color: #6a6e73
  • Hover color: #151515

Dark theme

  • Icon color: #d2d2d2
  • Hover color: #fff

@heyMP
Copy link
Contributor

heyMP commented Oct 15, 2021

@coreyvickery sounds good.

@wesruv I'm going to add these styles to the icon quick if that's ok?

@wesruv
Copy link
Contributor Author

wesruv commented Oct 18, 2021

@wesruv I'm going to add these styles to the icon quick if that's ok?

Sounds great, thanks sir!

@heyMP
Copy link
Contributor

heyMP commented Oct 19, 2021

@corey Here are the icon changes:
https://deploy-preview-1795--patternfly-elements.netlify.app/elements/pfe-clipboard/demo/

  • Light theme Icon color: #6a6e73; Hover color: #151515
  • Dark theme Icon color: #d2d2d2; Hover color: #fff

I also added a saturated theme where I used the following variables. I tried to semantically match them to their corresponding dark theme variables but they can be changed.

  • icon color: text--muted--on-saturated: #d2d2d2
  • icon color hover: text--on-saturated #fff

@coreyvickery
Copy link
Collaborator

@heyMP Looks great.

Comment on lines +74 to +92
// Attach variables to hover, focus states
// ignore disabled.
:host(:hover:not([disabled])),
:host(:focus:not([disabled])) {
.pfe-clipboard {
&__text {
color: pfe-local(Color--hover) !important;
}
&__icon {
// Customize icon color for pfe-icons
--pfe-icon--Color: #{pfe-local(icon--Color--hover)};
svg {
// Customize icon color of fallback svg icon
fill: pfe-local(icon--Color--hover) !important;
}
}
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Simplified our old focus,hover selectors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍🏼

Comment on lines +110 to +117
:host([on="dark"]) {
--pfe-clipboard--icon--Color: #{pfe-local(icon--Color--dark)};
--pfe-clipboard--icon--Color--hover: #{pfe-local(icon--Color--hover--dark)};
}

// Note: Hover states need to be defined after focus states
:host(:not([aria-disabled="true"]):hover),
:host(:not([aria-disabled="true"])) ::slotted(:hover) {
--pfe-clipboard--Color: #{pfe-local(Color--hover)};
:host([on="saturated"]) {
--pfe-clipboard--icon--Color: #{pfe-local(icon--Color--saturated)};
--pfe-clipboard--icon--Color--hover: #{pfe-local(icon--Color--hover--saturated)};
Copy link
Contributor

Choose a reason for hiding this comment

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

Explicitly adding theme context hooks for icon color. We don't have to include text color variables because that's automatically covered by broadcast variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍🏼

@heyMP
Copy link
Contributor

heyMP commented Oct 19, 2021

@wesruv I think almost ready. Sorry, this review took a while; but we have some really great improvements!

I think we'll just need to add this new copy-from API added to our docs and then we're good to go! 😁

@wesruv
Copy link
Contributor Author

wesruv commented Oct 19, 2021

Removed those unnecessary removeEventListeners

@heyMP
Copy link
Contributor

heyMP commented Oct 27, 2021

Hey, @wesruv. Would you be able to add the new "copy-from" attribute API to the docs?

@wesruv wesruv force-pushed the 1794-allow-pfe-clipboard-to-copy-arbitrary-things branch from 4fe2065 to e2dfcdc Compare November 5, 2021 17:26
Copy link
Contributor

@heyMP heyMP left a comment

Choose a reason for hiding this comment

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

LGTM!

@heyMP heyMP merged commit b15c476 into master Nov 5, 2021
@heyMP heyMP deleted the 1794-allow-pfe-clipboard-to-copy-arbitrary-things branch November 5, 2021 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AT passed Automated testing has passed demo Updating demo pages docs Documentation updates functionality Functionality, typically pertaining to the JavaScript. ready to merge styles An issue or PR pertaining only to CSS/Sass tests Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants