nandorojo / dripsy

🍷 Responsive, unstyled UI primitives for React Native + Web.
https://dripsy.xyz
MIT License
1.99k stars 77 forks source link

SVG Component #231

Closed fayez-nazzal closed 1 year ago

fayez-nazzal commented 1 year ago

Could we have a wrapper SVG Component that works with both React Native and Web?

I was able to integrate SVG with React Native using react-native-svg and react-native-svg-transformer. For web, it wouldn't be that difficult to implement using libraries like SVGR.

import Icon from "../svg/icon.svg";

export const App = () => {
    return (
        <SVG component={Icon} sx={{
                fill: "#277BC0",
                width: [24, 24, 32], 
                height: [24, 24, 32]
            }} 
        />
    );
}

Using this approach we make sure that styling is done the right way for each platform, this could save tons of time.

nandorojo commented 1 year ago

yeah it’s not a bad idea. for now i would use a combo of useDripsyTheme and useResponsiveValue

DubaniWarrior commented 1 year ago

can you show an example?

nandorojo commented 1 year ago
import Icon from "../svg/icon.svg";
import { useDripsyTheme, useResponsiveValue } from "dripsy";

export const App = () => {
  const height = useResponsiveValue([24, 24, 32]);
  const theme = useDripsyTheme();

  const width = useResponsiveValue((theme) => [theme.space.$3, theme.space.$4]);

  return (
    <SVG
      component={Icon}
      {...{
        fill: theme.colors.$primary,
        width,
      }}
      height={height}
    />
  );
};