Giter VIP home page Giter VIP logo

Comments (2)

christopherafbjur avatar christopherafbjur commented on August 18, 2024

Hi @JamesGriz will have a look at this in the upcoming weeks

from sanity-plugin-icon-picker.

christopherafbjur avatar christopherafbjur commented on August 18, 2024

Hi @JamesGriz! It seems to me based on the npx sanity-codegen script you ran that you're using the v2 version of the sanity-codegen and that you're using a sanity v3 studio based on the usage of defineField.

I tried installing/running sanity-codegen based on the instructions here (alpha version) which supports v3 projects and it generated the types for me correctly in my v3 sanity studio project.

This was my test setup:

./package.json

{
  "name": "sanity-project",
  "private": true,
  "version": "1.0.0",
  "main": "package.json",
  "license": "UNLICENSED",
  "scripts": {
    "dev": "sanity dev",
    "start": "sanity start",
    "build": "sanity build",
    "deploy": "sanity deploy",
    "deploy-graphql": "sanity graphql deploy"
  },
  "keywords": [
    "sanity"
  ],
  "dependencies": {
    "@fortawesome/free-brands-svg-icons": "^6.4.2",
    "@fortawesome/react-fontawesome": "^0.2.0",
    "@sanity/vision": "^3.14.5",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-is": "^18.2.0",
    "sanity": "^3.14.5",
    "sanity-plugin-icon-picker": "^3.2.2",
    "styled-components": "^5.3.9"
  },
  "devDependencies": {
    "@sanity/eslint-config-studio": "^3.0.0",
    "@types/react": "^18.0.25",
    "@types/styled-components": "^5.1.26",
    "eslint": "^8.6.0",
    "sanity-codegen": "^1.0.0-alpha.45",
    "typescript": "^4.9.5"
  },
  "prettier": {
    "semi": false,
    "printWidth": 100,
    "bracketSpacing": false,
    "singleQuote": true
  }
}

./schemas/index.tsx

import React from 'react'
import {defineField} from 'sanity'
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'
import {
  faSquareFacebook,
  faInstagram,
  faLinkedin,
  faTwitter,
} from '@fortawesome/free-brands-svg-icons'

const icons = {
  squareFacebook: faSquareFacebook,
  instagram: faInstagram,
  linkedin: faLinkedin,
  twitter: faTwitter,
}

export const schemaTypes = [
  {
    title: 'Icons',
    name: 'icons',
    type: 'document',
    fields: [
      defineField({
        title: 'Icon',
        name: 'icon',
        type: 'iconPicker',
        options: {
          configurations: [
            {
              title: 'FA Solid Icons',
              provider: 'fa-pro',
              icons: () =>
                Object.entries(icons).map(([name, Component]) => {
                  return {
                    name,
                    component: () => (
                      <div
                        style={{
                          display: 'flex',
                          alignItems: 'center',
                          justifyContent: 'center',
                          width: '25px',
                          height: '25px',
                        }}
                      >
                        <FontAwesomeIcon icon={Component} />
                      </div>
                    ),
                    tags: [name],
                  }
                }),
            },
          ],
        },
      }),
    ],
  },
]

As specified I then installed sanity-codegen npm i --save-dev sanity-codegen@alpha
and generated the types using npx sanity-codegen codegen.

from sanity-plugin-icon-picker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.