support custom coloring on amp-social-share SVG icon fills
According to https://amp.dev/documentation/examples/components/amp-social-share/?format=websites, icons colors can be styled using a css color attribute, same as the background-color attribute, however on the invoke of registerElement in amp-social-share-0.1.js the svg fill attribute of the default icons is fixed to '#fff' making the color attribute useless.
@paul-matthews
Thanks for filing this issue. It is possible to override the default styles using the SVG data.
Here is a sample with a non-white fill for the icon through custom styling:
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<title>My AMP Page</title>
<link rel="canonical" href="self.html" />
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-social-share" src="https://cdn.ampproject.org/v0/amp-social-share-0.1.js"></script>
<style amp-custom>
/* a custom sharing icon */
amp-social-share.custom-style {
border: 1px solid #ff0000;
background-color: #ffffff;
background-image: url('data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20512%20512%22%3E%3Cpath%20fill%3D%22%23ff0000%22%20d%3D%22M186.4%20142.4c0%2019-15.3%2034.5-34.2%2034.5%20-18.9%200-34.2-15.4-34.2-34.5%200-19%2015.3-34.5%2034.2-34.5C171.1%20107.9%20186.4%20123.4%20186.4%20142.4zM181.4%20201.3h-57.8V388.1h57.8V201.3zM273.8%20201.3h-55.4V388.1h55.4c0%200%200-69.3%200-98%200-26.3%2012.1-41.9%2035.2-41.9%2021.3%200%2031.5%2015%2031.5%2041.9%200%2026.9%200%2098%200%2098h57.5c0%200%200-68.2%200-118.3%200-50-28.3-74.2-68-74.2%20-39.6%200-56.3%2030.9-56.3%2030.9v-25.2H273.8z%22%2F%3E%3C%2Fsvg%3E');
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
</style>
</head>
<body>
<amp-social-share type="linkedin"
class="custom-style">
</amp-social-share>
</body>
</html>
Closing the issue for now, feel free to re-open.
So, basically in order to have style applied to this icon I would need to recreate the whole svg?...wow...
We have three options here:
- With the current implementation, we can only change the color is either by replacing the
background-imageor by using a filter (for examplefilter: brightness(0.2) sepia(1) hue-rotate(180deg) saturate(5);for a blue tone). - We can expose the
<svg>as a child instead of abackground-imagewhich will allow developers to usecolorandfillon it but that's a breaking change and requires a version bump - We can add a
colorattribute to the component and that requires setting thebackground-imageon the javascript side
Don't really understand why the background-image has any relation with the svg... can we just replace the fill attribute value with the color value of the element at the moment of the element creation?
It's not as straightforward because the the svg is currently added as a background-image (not as a child <svg> element). If we change to the latter implementation, we'd break websites that used to rely on styling background-image (hence the need for a version bump).
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.
Has anything changed with this or is still a no can do situation?
amp-social-share 1.0 allows for customizing the colors, but 0.1 does not: https://amp.dev/documentation/components/amp-social-share-v1.0/?format=websites#custom-styles
This does not work, not even with v1.0
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<title>My AMP Page</title>
<link rel="canonical" href="self.html" />
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<script async custom-element="amp-social-share" src="https://cdn.ampproject.org/v0/amp-social-share-1.0.js"></script>
<style amp-custom>
/* a custom sharing icon */
amp-social-share[type="linkedin"] {
color: blue;
background: red;
}
</style>
</head>
<body>
<amp-social-share type="linkedin"
class="custom-style">
</amp-social-share>
</body>
</html>
You will need to enable the "bento" or "bento-social-share" experiment somehow. This is the playground example using the invalid AMP way to do it for development. Here are valid AMP ways to enable experiments.
So, basically, if I want to style, I have to forget about valid AMP...right?
So, basically, if I want to style, I have to forget about valid AMP...right?
No, there are ways to enable experiments that are valid AMP, as documented in "Enable Experimental Features".
That said, the 1.0 version of amp-social-share will be planned to launch as valid AMP soon. I'll update this issue when that happens. Thank you!
Thanks to you! Ill wait! :)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.