Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Working slider component #4

Closed
kuatroka opened this issue Jun 16, 2023 · 12 comments
Closed

Working slider component #4

kuatroka opened this issue Jun 16, 2023 · 12 comments

Comments

@kuatroka
Copy link

Feature Description

Hi, I'm not sure it should go here but I don't know under which category to file it. I've been going through your tutorial and playing with Evidence. I would like to add a small contribution in case it might be interesting to somebody. It's a working version of a simple slider that changes values in the markdown when the slider is used. It's connected to a hypothetical result of a query, so it would be fully operational for a database of file connection, not just hardcoded values. It can illustrate how a simple binding mechanism works between Evidence, Svelte in HTML

Examples

Two files are needed:
Slider.svelte (put it in components folder)

<script>
	// export makes the variable a component property	
	export let value;
</script>

<input type='range' bind:value min=0 max=10 step=1 />

test-slider.md

<script>
    import Slider from '$lib/Slider.svelte';
    let score = 8;
</script>

## Using component **Slider** 
- It's a slider component that lives in `./components`  
- We import it here and bind its only attribute `value` to a variable `score` declared in `script` section
- Then we add some text that dynamically changes when we move the slider
- `value` comes from the imported `Slider.svelte`
- `score` is bound to this `value` variable

<Slider bind:value={score}/>

The score is: **{score}**

Screenshot
slider

@archiewood
Copy link
Member

archiewood commented Jun 16, 2023

Hey @kuatroka I think this is an ideal component to add into Evidence Labs (which is where we are hoping to put some of the more "experimental" features of evidence).

https://github.com/evidence-dev/labs

We'd welcome a PR there if you are open to it!

You'd need to

  • put the slider component somewhere in src/lib (perhaps in a folder called input?)
  • export the slider in src/lib/index.js
  • put your example code somewhere in /pages

@archiewood
Copy link
Member

Then anyone could use it if they add @evidence-dev/labs to their evidence.plugins.yaml

@kuatroka
Copy link
Author

Happy to help, but I've never done any PR or a proper programming. Let me check what exactly do I need to to here.

  1. I create a folder structure on my laptop - input/src/lib/components with Slider.svelte file in it?
  2. I create a folder structure on my laptop - input/pages with index.md file that references Slider.sveltein it?
  3. I don't understand what is the src/lib/index.js for or what to put there?
  4. How do I pass the code to you, do I just zip all these folders into one and attach it here?

Sorry if all of these questions are too naive, but honestly I'm not really familiar with all of this PR or other github terminology. I'm used to just copy/paste someone else's code and tweak it for my needs. Thanks

@archiewood
Copy link
Member

archiewood commented Jun 16, 2023

Ah gotcha. Let me give some more detail then!

  1. start by cloning the repository onto your computer: open an terminal and type git clone https://github.com/evidence-dev/labs
  2. open that folder, it will already have the folder structure ready for you to add your files
  3. src/lib/index.js should list any components that are in the src/lib folder that need to be accessible by users of the @evidence-dev/labs package. You can copy the current entry for FranceMap and change it for the component that you need to add
  4. Once you have the code running in the repository, you commit your code into your local repository
    • git add .,
    • git commit -m "adding my new slider component"
  5. Then you push your repo to github git push origin master (it will prompt you to create a fork of the evidence-dev/labs repository)
  6. And then open a pull request against the main evidence-dev/labs repo - this is where we can review the code, and then merge it in if it works!

This looks like quite a good generic guide: https://github.com/firstcontributions/first-contributions

@archiewood archiewood transferred this issue from evidence-dev/evidence Jun 16, 2023
@kuatroka
Copy link
Author

kuatroka commented Jun 16, 2023

  1. I'm trying to push the changes (from my branch called kuatroka-branch) but getting an auth error. Not sure what to do now.
 ~/D/d/labs (kuatroka-branch) [128]> git push -u origin kuatroka-branch
remote: Permission to evidence-dev/labs.git denied to kuatroka.
fatal: unable to access 'https://github.com/evidence-dev/labs.git/': The requested URL returned error: 403
  1. The way I've got the path to the imported component doesn't look very good to, but the FranceMap example is the same. I've tried to use the $lib prefix but would get errors all the time.
<script>
    import Slider from '../../../../../src/lib/charts/input/Slider.svelte';
    let score = 8;
</script>

@archiewood
Copy link
Member

archiewood commented Jun 16, 2023 via email

@archiewood
Copy link
Member

archiewood commented Jun 16, 2023 via email

@kuatroka
Copy link
Author

I've tried all of that, but still it errors out on me. Still the same authorisation issue.

origin  https://github.com/kuatroka/labs-fork.git (fetch)
origin  https://github.com/kuatroka/labs-fork.git (push)
 ~/D/d/labs-fork (kuatroka-branch)> git remote add upstream https://githu
b.com/evidence-dev/labs.git
 ~/D/d/labs-fork (kuatroka-branch)> git push upstream
remote: Permission to evidence-dev/labs.git denied to kuatroka.
fatal: unable to access 'https://github.com/evidence-dev/labs.git/': The requested URL returned error: 403

@kuatroka
Copy link
Author

How about I copy/paste the code for the two files ( Slider.svelte and index.md) here and that's it?
I don't want to become an "auth" burden

@hughess
Copy link
Member

hughess commented Jun 27, 2023

Hey @kuatroka, if you paste in the code here I can add the components to labs!

@kuatroka
Copy link
Author

Sure. Below are two files. The component and the markdown where the component is used.

src/lib/charts/input/Slider.svelte

<script>
	// export makes the variable a component property	
	export let value;
</script>

<input type='range' bind:value min=0 max=10 step=1 />

pages/slider/index.md

<script>
    import Slider from '../../../../../src/lib/charts/input/Slider.svelte';
    let score = 8;

</script>

## Using component **Slider** 
- It's a slider component that lives in `./components`  
- We import it here and bind its only attribute `value` to a variable `score` declared in `script` section
- Then we add some text that dynamically changes when we move the slider
- `value` comes from the imported `Slider.svelte`
- `score` is bound to this `value` variable

<Slider bind:value={score}/>

The score is: **{score}**

Here is the screenshot of the folder structure (just in case)
image

@hughess hughess changed the title NOT ISSUE - Small contribution - working slider component Working slider component Jun 29, 2023
@hughess
Copy link
Member

hughess commented Jul 4, 2023

Closed by #14! 🎉

@hughess hughess closed this as completed Jul 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants